HTTP Protocol Client

W

welcomestocontact

Hi,

I am writing http protocol to get some data from servers. If i was
using my localhost, getting replay from local and if want access other
remote sites, i am getting error. Please reply it

My localhost client script:::

Code: ( python )


import httplib

h = httplib.HTTP('localhost',80)

h.putrequest('GET','')

h.putheader('User-Agent','Lame Tutorial Code')

h.putheader('Accept','text/html')

h.endheaders()

errcode,errmsg, headers = h.getreply()

print errcode,errmsg, headers


f = h.getfile() # Get file object for reading data

data = f.read()

print data

f.close()





the Reply getting from this::::


403 Forbidden Date: Tue, 18 Sep 2007 05:20:36 GMT

Server: Apache/2.0.52 (Red Hat)

Accept-Ranges: bytes

Content-Length: 3985

Connection: close

Content-Type: text/html; charset=UTF-8

And some Html script




If I want to access other sites:::


import httplib

h = httplib.HTTP('http://Google.com',80)

h.putrequest('GET','')

h.putheader('User-Agent','Lame Tutorial Code')

h.putheader('Accept','text/html')

h.endheaders()



errcode,errmsg, headers = h.getreply()

print errcode,errmsg, headers


f = h.getfile() # Get file object for reading data

data = f.read()

print data

f.close()


I got the error like:::

Traceback (most recent call last):
File "c.py", line 6, in ?
h.endheaders()
File "/usr/lib/python2.3/httplib.py", line 712, in endheaders
self._send_output()
File "/usr/lib/python2.3/httplib.py", line 597, in _send_output
self.send(msg)
File "/usr/lib/python2.3/httplib.py", line 564, in send
self.connect()
File "/usr/lib/python2.3/httplib.py", line 532, in connect
socket.SOCK_STREAM):
socket.gaierror: (-2, 'Name or service not known')


How can I access Remote sites using http protocol . I did'nt write
server script.


Thanks And Regards
Allavarapu
 
T

thanosv

Hi,

I am writing http protocol to get some data from servers. If i was
using my localhost, getting replay from local and if want access other
remote sites, i am getting error. Please reply it

My localhost client script:::

Code: ( python )

import httplib

h = httplib.HTTP('localhost',80)

h.putrequest('GET','')

h.putheader('User-Agent','Lame Tutorial Code')

h.putheader('Accept','text/html')

h.endheaders()

errcode,errmsg, headers = h.getreply()

print errcode,errmsg, headers

f = h.getfile() # Get file object for reading data

data = f.read()

print data

f.close()

the Reply getting from this::::

403 Forbidden Date: Tue, 18 Sep 2007 05:20:36 GMT

Server: Apache/2.0.52 (Red Hat)

Accept-Ranges: bytes

Content-Length: 3985

Connection: close

Content-Type: text/html; charset=UTF-8

And some Html script

If I want to access other sites:::

import httplib

h = httplib.HTTP('http://Google.com',80)

h.putrequest('GET','')

h.putheader('User-Agent','Lame Tutorial Code')

h.putheader('Accept','text/html')

h.endheaders()

errcode,errmsg, headers = h.getreply()

print errcode,errmsg, headers

f = h.getfile() # Get file object for reading data

data = f.read()

print data

f.close()

I got the error like:::

Traceback (most recent call last):
File "c.py", line 6, in ?
h.endheaders()
File "/usr/lib/python2.3/httplib.py", line 712, in endheaders
self._send_output()
File "/usr/lib/python2.3/httplib.py", line 597, in _send_output
self.send(msg)
File "/usr/lib/python2.3/httplib.py", line 564, in send
self.connect()
File "/usr/lib/python2.3/httplib.py", line 532, in connect
socket.SOCK_STREAM):
socket.gaierror: (-2, 'Name or service not known')

How can I access Remote sites using http protocol . I did'nt write
server script.

Thanks And Regards
Allavarapu

1. First try setting the debug level with
h.set_debuglevel(9)
2. nslookup or dig google.com
3. are you behind a firewall ?

4. why not just use urllib.urlopen ? Its a lot easier and sets up all
the headers, and yes it can do POSTs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top