Question

I'm trying to send an http get request via the httplib, but I'm facing issues.

        conn = httplib.HTTPConnection("10.30.111.13/View")
        conn.request("GET", "/Default.aspx")
        res = conn.getresponse()

        if res.status == 200:
            print(res.status)

        else:
            print("Something went terribly wrong")

I get the following error:

TypeError (cannot concatenate 'str' and 'int' objects).

If put the next line of codes, it works no problem:

 conn = httplib.HTTPConnection("www.google.com")
 conn.request("GET", "/")

EDIT, here is a more detailed log I managed to pull out of my third party software (it restricts me in turn of python usability):

  File "<string>", line 3248, in initialization
  File "C:\python22\lib\httplib.py", line 701, in request
    self._send_request(method, url, body, headers)
  File "C:\python22\lib\httplib.py", line 723, in _send_request
    self.endheaders()
  File "C:\python22\lib\httplib.py", line 695, in endheaders
    self._send_output()
  File "C:\python22\lib\httplib.py", line 581, in _send_output
    self.send(msg)
  File "C:\python22\lib\httplib.py", line 548, in send
    self.connect()
  File "C:\python22\lib\httplib.py", line 516, in connect
    socket.SOCK_STREAM):
gaierror: (7, 'getaddrinfo failed')
Was it helpful?

Solution

I'm not someplace where I can test this now, but here's what I think:

You're passing only an IP address to a host field that's expecting a DNS address, not an IP address. That's why your second error listing says 'getaddrinfo' failed.

That said, I'm not sure how to use an IP address with httplib. Maybe try "http://10.30.111.13" instead. A good way to test it would be to replace your IP address above with Google's and see if you still get the error.

Maybe this will help -- sorry I can't say more!

OTHER TIPS

I have changed the IP address for a DNS address. I also removed any path/URI that were in the HTTPConnection() parameter. Now it works. Sorry for such an obvious question guys.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top