I am managing an app built by third parts in python.
I have this url dispatcher
urls += [(r'/path/objectAlpha/(.*)', objectAlphaHandler)] # this was made by third parts, it is expected to work
and this class
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)
...
I want to check that the app correctly receives the request and returns some response.
So I try to access that url with Postman
request type:
POST
URL:
http://<target_machine_ip>:<target_machine_port>/path/objectAlpha/
where <target_machine_port>
is 22.
I get this error from Postman response box
Parse Error: The server returned a malformed response
and when I click on "view in console" I see
POST http://<target_machine_ip>:22/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
What does Error: Parse Error: Expected HTTP/
mean?
I checked my app logs but it seems it is not handling any request, even if Postman indicates that the server is returning a (malformed) response.
I also tryed to chenge the target url to:
https...
but it returns
Error: write EPROTO 28427890592840:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:../../third_party/boringssl/src/ssl/tls_record.cc:242:
which I found out it indicates I should stick with HTTP
Then I tried also:
http://<target_machine_ip>/path/objectAlpha/
and
<target_machine_ip>/path/objectAlpha/
which generically return:
Error: connect ECONNREFUSED <target_machine_ip>:80
I also tryed to substitute line
urls += [(r'/path/objectAlpha/(.*)', objectAlphaHandler)]
with
urls += [(r'/path/objectAlpha/', objectAlphaHandler)]
and
urls += [(r'/path/objectAlpha', objectAlphaHandler)]
but none of these worked.
What is wrong? How can I fix it?
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.
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/objectAlpha"
and I got:
* 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
SOLVED
Since the exposed API has been built by third parts for internal use, it is not exposed to the public.
I did not know that, so in the request URL I had put the well-known port number for HTTP requests, the number 22 (see the list of well-known port numbers.).
To solve the problem, in the request URL, I changed the <target_machine_port>
to the port on which the API is actually exposed.
request type:
POST
URL:
http://<machine_ip>:<target_machine_port>/path/objectAlpha/