分析错误:服务器返回了格式错误的响应-错误:分析错误:尝试使用postman访问我的某个应用程序URL时,应为HTTP/ -

uinbv5nw  于 2022-11-07  发布在  Postman
关注(0)|答案(1)|浏览(324)

我正在管理一个由third parts用python构建的应用程序。
我有这个网址调度程序

urls += [(r'/path/objectAlpha/(.*)', objectAlphaHandler)]  # this was made by third parts, it is expected to work

而这门课

class objectAlphaHandler(BaseHandler):

    def __init__(self, application, request,**kwargs):
        super(objectAlphaHandler, 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/objectAlpha/

我从Postman响应框中收到此错误
分析错误:服务器返回了格式错误的响应
当我单击“在控制台中查看”时,我看到

POST http://machine_ip>:<machine_port>/path/objectAlpha/
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: xx.xxx.x.xx: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://<machine_ip>/path/objectAlpha/

<machine_ip>/path/objectAlpha/

它通常返回:

Error: connect ECONNREFUSED <machine_ip>:80

我也试着用

urls += [(r'/path/objectAlpha/(.*)', objectAlphaHandler)]

urls += [(r'/path/objectAlpha/', objectAlphaHandler)]

urls += [(r'/path/objectAlpha', objectAlphaHandler)]

但这些都不起作用。
出什么问题了?我该怎么解决?

更新

显然,根据 Postman Github上的这个线程,这个问题只发生在 Postman 桌面上,而不是在 Postman 浏览器上。
所以我试着在我的浏览器上发送请求表 Postman ,但我得到

Cloud Agent Error: Can not send requests to reserved address. Make sure address is publicly accessible or select a different agent.

因为根据this other thread
Postman网站无法向您的本地主机发送请求。它首先需要使用Postman桌面客户端连接到您的PC
即使我按照答案中的指示去做
运行它[ndr. Postman桌面],然后在浏览器中转到Postman工作区-〉发送请求,它就会工作。
我还是一样

Error: Parse Error: Expected HTTP/

在Postman桌面和Postman浏览器上。

更新

继续调试,我尝试从我的终端在该URL上转换一个curl:

myuser@mymachine-VirtualBox:~$ curl --verbose "http://<target_machine_ip>:<target_machine_port>/path/objectAlpha"

我得到了:


* 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
wz1wpwve

wz1wpwve1#

已解决
由于公开的api是由第三方构建供内部使用的,因此不会公开。
我并不知道这一点,所以在请求URL中我已经为HTTP请求设置了众所周知的端口号,即22号(请参见list of well-known port numbers.)。
为了解决这个问题,在请求URL中,我将<target_machine_port>更改为实际公开API的端口。

相关问题