我正在开发一个充当桥梁的服务器,我向他发送请求,然后我再次发送给api, 当我使用localhost转换此代码时,它正在运行,我从api得到答案。 但是当我用我的服务器转动它时,我没有得到任何回应。 我认为这取决于等待时间,但我把睡眠时间设为10秒仍然没有答案。 有什么想法吗?
def do_POST(self):
print( "incomming http: ", self.path )
content_length = int(self.headers['Content-Length']) # <--- Gets the size of data
post_data = self.rfile.read(content_length) # <--- Gets the data itself
#print(str(post_data))
print("Got data.")
response = bytes("Data Received.", "utf-8")
self.send_response(200)
self.send_header("Content-Length", str(len(response)))
self.end_headers()
self.wfile.write(response) #send response
test_name = "Jhon Doe"
respserver = getId(test_name)
try :
print("sending to the other server..")
idname = int(respserver)
msg = post_data.decode("utf-8")
js = json.loads(msg)
respserver = sendIntRR(idname, js)
print("waiting a response")
sleep(1)
print("Api : ", respserver)
except :
print("ExternalId : ", test_name)
print(respserver)
请求从此处发送:
def sendIntRR (id : int, msg : str) -> str:
url = apiurl + "collect/" + str(id)
querystring = {"period":"300000","filter":"3","returnList":"True"}
payload = msg
headers = {
'authorization': bearerClient,
'content-type': "application/json",
'cache-control': "no-cache",
}
response = requests.api.request('post', url, data=payload, headers=headers,params=querystring, json=None, verify=False)
return(response.text)
我在服务器终端获得了什么:
sending to the other server..
ExternalId : Jhon Doe
8
非常感谢,G.B
答案 0 :(得分:0)
我得到的答案就是睡眠,一旦我取消睡眠,那就有效,不知道如何解释它但现在有效