Is it possible to do a post request from one route in flask to another route? A user sends in data I will look up data then submit that data to another route. Getting Internal Server Error log just has failed (111: Connection refused) while connecting to upstream. I know the route works if i remove the requests line I see found you.
#app.route('/route/<string:uname>', endpoint = 'uname')
def uname():
d={}
d['fname']='data'
d['lname']='data'
requests.post(url='https:site.com/test/', data = data)
return 'found you'
#app.route('test', endpoint = 'test', methods = ['POST','GET'])
def test():
return "submitted to test"
***** Added verify=False to the requests.post line and it just hangs and ties up the service. I have to restart the service for the site to start working.
Related
I have did integration for Socket.io and WordPress CF7. Working properly as expected I have an issue with multiple domains.
For eg. I have 15 domains like,
example.com
stage.example.com
stage2.example.com
newdmain.com
mydomain.com
Server running on node.myserver.com
Now, I want to create request from client and response on same client. As I check when I run websocket from server and hit api will broadcast on all connected domain.
app.post('/contact-webhook', function(req, res){
// check if it's a valid request from WooCommerce
if (!req.headers['Secret-Key']) return res.status(401).end()
// parse our data
const payload = req.body
// we could use any event handler here
socketIO.emit("newNotification", payload)
// end response
res.status(200).end()
})
When raise request then server will broadcast on all server.
Refer question : socket.io - send notification to admin when order place in WooCommerce
//How do I send Request in Robot Framework It Gives 500 server error
//This is the request body that I want to send
{
"destinationFaxNumber": "9546599326",
"documentCount": 1
}
*** Variables ***
${base_Url}= https://07du47r041.execute-api.us.com/dev/v1/outbound
*** Test Cases ***
Send Fax Request
${headers}= create dictionary Authorization=${Token} Content-Type=application/json
#${file_data}= Get Binary File D:TestCases/SendFax.json //commented
${body}= create dictionary destinationFaxNumber=9546599326 documentCount=1
create session faxsession ${base_Url} headers=${headers}
log to console ${body}
${response}= Post On Session faxsession /fax data=${body} headers=${headers}
However I'm getting below error
HTTP Error: 500 Server Error: Internal Server Error for url: https://07du47r041.execute-api.us.com/dev/v1/outbound/fax
If postman works and RF does not, the request payload is 99.99% at fault. Capture network traffic with succesful and failing requests and compare what is different.
For example, if you have access to linux box or any machine with netcat, start nc on some port and point the url from postman and rf into that NC socket and see the request differences right in the console of nc.
So I am building few mock servers to simulate servers that are involved in actual code.
Since there are few handshakes happening between servers during authentication process, it essentially looks like a ping pong between servers.
Here is how it looks --
Server1 -> Connect api on Server 2
Authorize on Server 1 <- Connect api on Server 2
Authorize on Server 1 -> Calls /Callback Endpoint on Server 1
<- Server 1 sends OK to Server 2(ends handshake with OK)
With this in mind I have following code written to simulate the handshake
# Server 2 (main.py)
#app.get("/v1/connect")
def connect():
httpx.get("server1/authorize")
#app.get("/callback")
def do_callback():
return "OK"
#Server 1 (main.py)
#app.get("/v1/authorize")
def do_authorize():
httpx.get("server1/callback")
But I notice error when I try to start the interactions between Server 1 and 2 by calling Connect endpoint on Server2, Server 1 throws httpcore exception while Server 2 tries to call Server 1's authorize endpoint
Any idea what is wrong here
I am using fastApi to build the mockservers
I have a simple fastapi server which is supposed to accept a request body that consists of a single string. It is supposed to take that string and send it to another module and get the return result, then send that back to the client.
Things on the client side seem to be working fine, but for some reason the call from the server to the other module isn't working. I suspect that I am not actually sending to the module what I think I am, and that I have to modify the call in some way. I want to stop it in the debugger so I can see exactly what the request and response objects look like.
I know how to set it up to debug the server, but not how to then send it a request body while in the debugger.
The server looks like this, with a main block added so I can debug it directly:
import uvicorn
from fastapi import FastAPI
from pydantic import BaseModel
from annotate import AnnotationModule
from fastapi.testclient import TestClient
app = FastAPI()
class Sentence(BaseModel):
text: str
print('Spinning up resources.')
am = AnnotationModule(wsd_only=True)
print('Everything loaded. Ready.')
#app.post("/annotate/")
async def read_item(sentence: Sentence):
return am.annotate(sentence.text)
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
I can set a breakpoint and run this, but how do I send it a request body so I can see it working?
I tried using this client code, but it didn't work:
import requests
# api-endpoint
URL = "http://0.0.0.0:8000/annotate"
PARAMS = {"text": "This is a test sentence."}
# sending get request and saving the response as response object
annotation_dict = requests.post(url = URL, json = PARAMS)
Running this while the server is sitting in the debugger, I get:
requests.exceptions.ConnectionError: HTTPConnectionPool(host='0.0.0.0', port=8000): Max retries exceeded with url: /annotate (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fd926ed5f90>: Failed to establish a new connection: [Errno 61] Connection refused'))
So, how can I debug it while observing it taking and processing a request? If it matters, I am doing this in vscode.
I have a nodejs websocket AWS lambda endpoint (Api Gateway) set up and it connects and can echo messages back. During initial connection, I save the endpoint and connection_id to a database. That gets saved just fine. If I open a browser client, and connect to the websocket endpoint, I can connect successfully, and send a message from the browser successfully - I have code to echo the message back, and it works.
Now, in another nodejs lambda, one that provides a REST endpoint, I have code that loads the connection_id from the database and does this:
// 'connection' is loaded successfully from DB (I log it and see the right values)
let api = new AWSSDK.ApiGatewayManagementApi({apiVersion: '2018-11-29', endpoint: connection.endpoint});
await api.postToConnection({
ConnectionId: connection.connection_id,
Data: JSON.stringify({ message: 'Hello World' })
}).promise();
However, the code in the REST endpoint (code above) always gets a 410 error in the postToConnection. I know the connection is still active, since I can connect to it and ping it in a browser client just prior to testing the REST API above.
Is it not possible to post to a websocket connection from a non-websocket lambda?
I think you should use this to send messages from the backend to your clients.
To send a callback message to the client, use:
POST
https://{api-id}.execute-api.us-east-1.amazonaws.com/{stage}/#connections/{connection_id}
https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html