Start New Discussion within our Software Development Community

import httplib
conn = httplib.HTTPConnection("<A href="",80">",80)
conn.request("GET", "/index.php")
r1 = conn.getresponse()
print r1.status, r1.reason


where I test it,it show errors as below:
Traceback (most recent call last):
File "E:\Program\demo\src\", line 6, in <module>
conn.request("GET", "/index.php")
File "C:\Python25\Lib\", line 862, in request
self._send_request(method, url, body, headers)
File "C:\Python25\Lib\", line 885, in _send_request
File "C:\Python25\Lib\", line 856, in endheaders
File "C:\Python25\Lib\", line 728, in _send_output
File "C:\Python25\Lib\", line 695, in send
File "C:\Python25\Lib\", line 663, in connect
socket.gaierror: (11001, 'getaddrinfo failed')

can any body help me ?

Two things.

1. Your line

("<A href="",80">",80)

is malformed because you have nested "" marks. Python always takes the first " to be the start of a string and the next " to be the end. (unless the first " is part of """). So if you need a complicated string, you need to do

('<A HREF="",80')

2. Actually, I think the syntax of HTTPConnection is a lot simpler. If I understand you right, I think you want this:

import httplib
conn = httplib.HTTPConnection("",80)
conn.request("GET", "/index.php")
r1 = conn.getresponse()
print r1.status, r1.reason

2.5. If you enclose your code in [ code = Python ] [ / code ] tags, without the spaces, your code will pretty print like mine did, and preserve the indentation that is necessary for Python code.

Hope it helps,

This article has been dead for over six months. Start a new discussion instead.