473,574 Members | 2,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HTTP Protocol

12 New Member
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:::

Expand|Select|Wrap|Line Numbers
  1. import httplib
  2. h = httplib.HTTP('localhost',80)
  3. h.putrequest('GET','')
  4. h.putheader('User-Agent','Lame Tutorial Code')
  5. h.putheader('Accept','text/html')
  6. h.endheaders()
  7.  
  8. errcode,errmsg, headers = h.getreply()
  9. print errcode,errmsg, headers
  10.  
  11.  
  12.  
  13. f = h.getfile() # Get file object for reading data
  14. data = f.read()
  15. print data
  16. f.close()
  17.  
  18.  
  19. the Reply getting from this::::
  20.  
  21.  
  22.  
  23.  403 Forbidden Date: Tue, 18 Sep 2007 05:20:36 GMT
  24. Server: Apache/2.0.52 (Red Hat)
  25. Accept-Ranges: bytes
  26. Content-Length: 3985
  27. Connection: close
  28. Content-Type: text/html; charset=UTF-8
  29.    And some Html script
  30.  
  31.  
  32. If I want to access other sites:::
  33.  
  34.        import httplib
  35. h = httplib.HTTP('http://Google.com',80)
  36. h.putrequest('GET','')
  37. h.putheader('User-Agent','Lame Tutorial Code')
  38. h.putheader('Accept','text/html')
  39. h.endheaders()
  40.  
  41. errcode,errmsg, headers = h.getreply()
  42. print errcode,errmsg, headers
  43.  
  44. f = h.getfile() # Get file object for reading data
  45. data = f.read()
  46. print data
  47. f.close()
  48.  
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_outp ut()
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_STR EAM):
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
Sep 18 '07 #1
5 5678
bartonc
6,596 Recognized Expert Expert
This module defines classes which implement the client side of the HTTP and HTTPS protocols. It is normally not used directly -- the module urllib uses it to handle URLs that use HTTP and HTTPS.
11.4 urllib -- Open arbitrary resources by URL
Sep 18 '07 #2
allavarapu
12 New Member
11.4 urllib -- Open arbitrary resources by URL


I also tried for this url script::

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. import urllib
  4.  
  5. proxies = proxies={'http': '192.168.0.2:80'}
  6.  
  7. f = urllib.urlopen("http://www.google.com",proxies={})
  8. buf = f.read()
  9. print buf
  10. f.close()    
  11.  
  12.  
Hear also it say the same Like
........
IOError: [Errno socket error] (-2, 'Name or service not known')

If I use IP addres Insted of this www.google.com Like::

Expand|Select|Wrap|Line Numbers
  1. import urllib
  2.  
  3. proxies = proxies={'http': '192.168.0.2:80'}
  4.  
  5. f = urllib.urlopen("http://209.85.135.147",proxies={})
  6. buf = f.read()
  7. print buf
  8. f.close()
  9.  
  10.  
I am getting different error Like:::

raceback (most recent call last):
File "url.py", line 5, in ?
f = urllib.urlopen( "http://209.85.135.147" ,proxies={})
File "/usr/lib/python2.3/urllib.py", line 76, in urlopen
return opener.open(url )
File "/usr/lib/python2.3/urllib.py", line 181, in open
return getattr(self, name)(url)
File "/usr/lib/python2.3/urllib.py", line 297, in open_http
h.endheaders()
File "/usr/lib/python2.3/httplib.py", line 712, in endheaders
self._send_outp ut()
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 548, in connect
raise socket.error, msg
IOError: [Errno socket error] (110, 'Connection timed out')


Please Help for this.

Thanks
Allavarapu
Sep 19 '07 #3
bartonc
6,596 Recognized Expert Expert
I also tried for this url script::

Expand|Select|Wrap|Line Numbers
  1. import urllib
  2.  
  3. proxies = proxies={'http': '192.168.0.2:80'}
  4.  
  5. f = urllib.urlopen("http://www.google.com",proxies={})
  6. buf = f.read()
  7. print buf
  8. f.close()    
Please Help for this.

Thanks
Allavarapu
You have a small confusion over python syntax here. Try it this way:
Expand|Select|Wrap|Line Numbers
  1. import urllib
  2.  
  3. proxies = {'http': '192.168.0.2:80'}
  4.  
  5. f = urllib.urlopen("http://www.google.com", proxies=proxies)
  6. buf = f.read()
  7. f.close()
  8. print buf    
  9.  
  10.  
Sep 19 '07 #4
allavarapu
12 New Member
You have a small confusion over python syntax here. Try it this way:
Expand|Select|Wrap|Line Numbers
  1. import urllib
  2.  
  3. proxies = {'http': '192.168.0.2:80'}
  4.  
  5. f = urllib.urlopen("http://www.google.com", proxies=proxies)
  6. buf = f.read()
  7. f.close()
  8. print buf    
  9.  
  10.  

Hello

I tried your suggested code. I got the error::

Traceback (most recent call last):
File "first.py", line 5, in <module>
f = urllib.urlopen( "http://www.google.com" , proxies=proxies )
File "/usr/local/lib/python2.5/urllib.py", line 82, in urlopen
return opener.open(url )
File "/usr/local/lib/python2.5/urllib.py", line 185, in open
return self.open_unkno wn_proxy(proxy, fullurl, data)
File "/usr/local/lib/python2.5/urllib.py", line 204, in open_unknown_pr oxy
raise IOError, ('url error', 'invalid proxy for %s' % type, proxy)
IOError: [Errno url error] invalid proxy for http: '192.168.0.2:80 '

Please Help
Thanks for sending reply

Divakar
Sep 19 '07 #5
allavarapu
12 New Member
Hello

I tried your suggested code. I got the error::

Traceback (most recent call last):
File "first.py", line 5, in <module>
f = urllib.urlopen( "http://www.google.com" , proxies=proxies )
File "/usr/local/lib/python2.5/urllib.py", line 82, in urlopen
return opener.open(url )
File "/usr/local/lib/python2.5/urllib.py", line 185, in open
return self.open_unkno wn_proxy(proxy, fullurl, data)
File "/usr/local/lib/python2.5/urllib.py", line 204, in open_unknown_pr oxy
raise IOError, ('url error', 'invalid proxy for %s' % type, proxy)
IOError: [Errno url error] invalid proxy for http: '192.168.0.2:80 '

Please Help
Thanks for sending reply

Divakar



Hello bartonc,

It is problem with Firewall. It is blocking me to access the network. If i run the script from public IP it's working.

But i have one doubt about this, i can access websites form mozilla firefox or other browser. How can i run my script with in my private network, there is any possiblety to access http protocol.


Thanks
divakar
Sep 20 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
15466
by: Justin Malloy | last post by:
I am using the System.Net.Webclient to try and download an XML file from a website but am receiving a HTTP protocol error when running the DownloadFile() sub routine. I did a HTTP trace using internet explorer to see what is happening in the request and it looks as though the request originates using HTTP/1.1 to an IIS server authenticates...
2
2209
by: Rujuta Gandhi | last post by:
Hi All, I am facing a very crucial problem. Im developing a web application using .net studio 2005(beta). I want my Login.aspx page to be secured(https) for encrypted login information transfer. I modified web.config and properties of Login page from IIS server. And now when ever the execution is redirected to Login.aspx It is having...
5
6015
by: Henrik | last post by:
Hi, I am trying to read some industrial webservers using the HTTP/CGI webequest like this: wrs = (HttpWebRequest)WebRequest.Create(HTTP/CGI-string); mwst = (HttpWebResponse wrs.GetResponse(); str = mwst.GetResponseStream(); This usually works fine but on some servers i get:
0
1428
by: Helen | last post by:
Hi, I am trying to use a .Net WebClient object to read data from a url, but I am getting the following error: System.Net.HttpWebRequest.CheckFinalStatus() System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) System.Net.HttpWebRequest.GetResponse() System.Net.WebClient.OpenRead(String address)
10
1791
by: Mat | last post by:
I would like to write a client-server application which will communicate through HTTP PROTOCOL . essentially, client will send and received xml files. is it possible?? I want to use http protocol to avoid firewall problems.
1
7727
by: Dan W. | last post by:
Does anyone have any experience with this problem. I am trying to post about 20 fields of information to another server using System.Net.WebClient.UploadData. This works fine for some servers but one in particular is causing the exception "The underlying connection was closed: The server committed an HTTP protocol violation" to be thrown. ...
1
2409
by: Khadim | last post by:
I m using HTTWebResponse which is running smoothly on my system which is behing a proxy server. When I run the application with Live IP it gives "HTTP Protocol violation error" I can't use 'useUnsafeHeaderParsing' because it is not recognized by framework without sp3. I have urlencoded my data... its a simple get method with no...
2
1988
by: rn5a | last post by:
Using CDO.MESSAGE, can e-mails in ASP be sent using the HTTP protocol instead of the SMTP protocol? If yes, then how? If no, then is there any other way to send e-mails in ASP using the HTTP protocol?
0
931
by: allavarapu | last post by:
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::: import httplib h = httplib.HTTP('localhost',80) h.putrequest('GET','')
1
319
by: welcomestocontact | last post by:
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 )
0
7808
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8063
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8101
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5626
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5302
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3742
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1062
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.