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

conn.close()


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


can any body help me ?

Two things.

1. Your line

("<A href="http://www.python.org",80">http://www.python.org",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="http://www.python.org",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("http://www.python.org",80)
conn.request("GET", "/index.php")
r1 = conn.getresponse()
print r1.status, r1.reason
conn.close()

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,
Jeff

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.