http - How to push GET POST requests using python through proxy? -


i not able pass through proxy server make http requests , have tried 2 ways shown below returns proxy auth fail message our proxy server.

import requests  proxies = { 'http': 'http://ed6a1505:34103@200.200.200.5:6588/' }  r=requests.get('http://www.google.com', proxies=proxies)  print r.status_code, r.content, r.text 

above code sends web page our proxy server stating need authenticate, though have added correct id , password in code.

and second method below gives following error[error shown below following code]:

import httplib import urllib  proxyhost='http://ed14-19:31036@200.200.200.5' proxyport='6588' httpconn = httplib.httpconnection(proxyhost, proxyport)  #httpconn = httplib.httpconnection('http://www.google.com:80')  httpconn.set_tunnel('www.google.com', 80) httpconn.request('post', 'http://www.google.com') resp = httpconn.getresponse()  print resp.status, resp.reason resp_data = resp.read() print resp_data  httpconn.close() 

this gives following :

astitva@astitva-vostro-3446:~$ python httplib1.py  traceback (most recent call last):  file "httplib1.py", line 11, in <module>   httpconn.request('post', 'http://www.google.com')  file "/usr/lib/python2.7/httplib.py", line 979, in request   self._send_request(method, url, body, headers)  file "/usr/lib/python2.7/httplib.py", line 1013, in _send_request   self.endheaders(body)  file "/usr/lib/python2.7/httplib.py", line 975, in endheaders   self._send_output(message_body)  file "/usr/lib/python2.7/httplib.py", line 835, in _send_output   self.send(msg)  file "/usr/lib/python2.7/httplib.py", line 797, in send   self.connect()  file "/usr/lib/python2.7/httplib.py", line 778, in connect   self.timeout, self.source_address)  file "/usr/lib/python2.7/socket.py", line 553, in create_connection   res in getaddrinfo(host, port, 0, sock_stream): socket.gaierror: [errno -2] name or service not known 

you might looking this:

import urllib2  proxy_handler = urllib2.proxyhandler({'http':'http://ed14-19:31036@200.200.200.5:6588'}) opener = urllib2.build_opener(proxy_handler)  req = urllib2.request("http://wwww.google.com") try :     response = opener.open(req)     status = response.getcode()     print response.read() except urllib2.urlerror, e:     print "[error] exit status: %s " %  e.code 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -