pythonpython-3.xhttp.client

How to get an HTTP response with specific port using http.client?


I tried to get a page contents of the following URL

http://username:5000/check/e9549df676ecca6344ad8ba068d05a6d

So I tried to write the following script but with no success

import http.client

conn = http.client.HTTPSConnection("username",5000)
conn.request("GET", "/check/e9549df676ecca6344ad8ba068d05a6d")
r1 = conn.getresponse()
print(r1.read())

When I run the script it would just hang, could anyone help me please?

Thank you


Solution

  • The address you are trying to connect to uses HTTP. You are connecting via HTTPS to the server using HTTPSConnection. If the server does not accept an HTTPS connection on port 5000, an error is thrown as the library does not automatically downgrade or change the protocol.

    Try to change http.client.HTTPSConnection to http.client.HTTPConnection.