我正在管理由 python 中的第三方構建的應用程式。
我有這個 url 調度程式
urls = [(r'/path/objectA/(.*)', ObjectAHandler)] # this was made by third parts, it is expected to work
和這堂課
class ObjectAHandler(BaseHandler):
def __init__(self, application, request, **kwargs):
super(ObjectAHandler, self).__init__(application, request, **kwargs) # do the init of the basehandler
@gen.coroutine
def post(self, action=''):
response = {}
...
response = yield self.my_method(json_data)
...
self.write(json.dumps(response))
def my_method(self, json_data)
...
我想檢查應用程式是否正確接收請求并回傳一些回應。
所以我嘗試使用 Postman 訪問該網址
請求型別:
POST
網址:
http://<machine_ip>:<machine_port>/path/objectA/
我從郵遞員回應框中收到此錯誤
決議錯誤:服務器回傳格式錯誤的回應
當我點擊“在控制臺中查看”時,我看到了
POST http://machine_ip>:<machine_port>/path/objectA/ Error: Parse Error: Expected HTTP/ Request Headers Content-Type: application/json User-Agent: PostmanRuntime/7.28.4 Accept: */* Postman-Token: d644d7dd-699b-4d77-b32f-46a575ae31fc Host: 10.133.5.37:22 Accept-Encoding: gzip, deflate, br Connection: keep-alive Request Body
是什么Error: Parse Error: Expected HTTP/意思?
我檢查了我的應用程式日志,但它似乎沒有處理任何請求,即使 Postman 指示服務器正在回傳(格式錯誤的)回應。
我還嘗試將目標網址更改為:
https...
但它回傳
Error: write EPROTO 28427890592840:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:../../third_party/boringssl/src/ssl/tls_record.cc:242:
我發現它表明我應該堅持使用 HTTP
然后我也嘗試了:
http://<machine_ip>/path/objectA/
和
<machine_ip>/path/objectA/
通常回傳:
Error: connect ECONNREFUSED <machine_ip>:80
I also tryed to substitute line
urls = [(r'/path/objectA/(.*)', ObjectAHandler)]
with
urls = [(r'/path/objectA/', ObjectAHandler)]
and
urls = [(r'/path/objectA', ObjectAHandler)]
but none of these worked.
What is wrong? How can I fix it?
UPDATE
Apparently, according to this thread on Postman Github, the problem happens only on Postman Desktop and not on Postman on browser.
So I tryed to send the request form Postman on my browser but I get
Cloud Agent Error: Can not send requests to reserved address. Make sure address is publicly accessible or select a different agent.
because, according to this other thread,
Postman Website cannot send a request to your computer's localhost. It first needs to connect to your PC with the Postman desktop client
and even if I follow the indications in that answer
Run it [ndr. Postman desktop], then go to the Postman workspace in your browser -> send the request and it will work.
I still get the same
Error: Parse Error: Expected HTTP/
on both Postman Desktop and Postman on browser.
UPDATE
Going on debugging, I tryed to cast a curl on that URL from my terminal:
myuser@mymachine-VirtualBox:~$ curl --verbose "http://<target_machine_ip>:<target_machine_port>/path/objectA"
我得到了:
* Trying <target_machine_ip>:<target_machine_port>... * Connected to <target_machine_ip> (<target_machine_ip>) port <target_machine_port> (#0) > GET /orkpos5/receipt HTTP/1.1 > Host: <target_machine_ip>:<target_machine_port> > User-Agent: curl/7.74.0 > Accept: */* > * Received HTTP/0.9 when not allowed * Closing connection 0 curl: (1) Received HTTP/0.9 when not allowed
uj5u.com熱心網友回復:
解決了
由于公開的api是由第三方構建供內部使用的,所以不對外公開。
我不知道,所以我在請求 URL 中輸入了 HTTP 請求的知名埠號,即數字 22(請參閱知名埠號串列。)。
為了解決這個問題,在請求 URL 中,我將 更改<target_machine_port>為實際暴露 api 的埠。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/414839.html
標籤:
