httplib

How to fix httplib.BadStatusLine exception?

眉间皱痕 提交于 2019-11-28 00:15:49
URL = "MY HTTP REQUEST URL" XML = "<port>0</port>" parameter = urllib.urlencode({'XML': XML}) response = urllib.urlopen(URL, parameter) print response.read() IOError: ('http protocol error', 0, 'got a bad status line', None) I am trying to send XML to a server and get back XML. Is there any way to fix / ignore this exception? I know that the status line is empty which is raising this error. Try to have a look what your server actually returns! It probably isn't a valid HTTP response. You could use something like this to send a raw http request to the server: from socket import socket host =

Python httplib ResponseNotReady

那年仲夏 提交于 2019-11-27 19:00:28
I'm writing a REST client for elgg using python, and even when the request succeeds, I get this in response: Traceback (most recent call last): File "testclient.py", line 94, in <module> result = sendMessage(token, h1) File "testclient.py", line 46, in sendMessage res = h1.getresponse().read() File "C:\Python25\lib\httplib.py", line 918, in getresponse raise ResponseNotReady() httplib.ResponseNotReady Looking at the header, I see ('content-length', '5749'), so I know there is a page there, but I can't use .read() to see it because the exception comes up. What does ResponseNotReady mean and why

How to send and receive HTTP POST requests in Python [closed]

﹥>﹥吖頭↗ 提交于 2019-11-27 14:51:01
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . I need a simple Client-side method that can send a boolean value in a HTTP POST request, and a Server-side function that listens out for, and can save the POST content as a var. I am having trouble finding information on how to use the httplib . Please show me a simple example,

Tunneling httplib Through a Proxy

混江龙づ霸主 提交于 2019-11-27 12:37:50
问题 I am trying to figure out how to send data to a server through a proxy. I was hoping this would be possible through tor but being as tor uses SOCKS it apparently isn't possible with httplib (correct me if I am wrong) This is what I have right now import httplib con = httplib.HTTPConnection("google.com") con.set_tunnel(proxy, port) con.send("Sent Stuff") The problem is, it seems to freeze when the tunnel is set. Thanks for your help. 回答1: If you want to use http proxy, it should be like this:

How do I get the IP address from a http request using the requests library?

ぐ巨炮叔叔 提交于 2019-11-27 12:26:57
I am making HTTP requests using the requests library in python, but I need the ip address from the server that responded the http request and I'm trying to avoid to make two calls (and possibly having a different ip address from the one that responded the request. Is that possible? Does any python http library allows me to do that? ps: I also need to make HTTPS requests and to use an authenticated proxy. Update 1: Example: import requests proxies = { "http": "http://user:password@10.10.1.10:3128", "https": "http://user:password@10.10.1.10:1080", } response = requests.get("http://example.org",

httplib CannotSendRequest error in WSGI

南楼画角 提交于 2019-11-27 09:03:35
I've used two different python oauth libraries with Django to authenticate with twitter. The setup is on apache with WSGI. When I restart the server everything works great for about 10 minutes and then the httplib seems to lock up (see the following error). I'm running only 1 process and 1 thread of WSGI but that seems to make no difference. I cannot figure out why it's locking up and giving this CannotSendRequest error. I've spent a lot of hours on this frustrating problem. Any hints/suggestions of what it could be would be greatly appreciated. File "/usr/lib/python2.5/site-packages/django

error: can't start new thread

ⅰ亾dé卋堺 提交于 2019-11-27 08:18:44
I have a site that runs with follow configuration: Django + mod-wsgi + apache In one of user's request, I send another HTTP request to another service, and solve this by httplib library of python. But sometimes this service don't get answer too long, and timeout for httplib doesn't work. So I creating thread, in this thread I send request to service, and join it after 20 sec (20 sec - is a timeout of request). This is how it works: class HttpGetTimeOut(threading.Thread): def __init__(self,**kwargs): self.config = kwargs self.resp_data = None self.exception = None super(HttpGetTimeOut,self)._

python httplib/urllib get filename

隐身守侯 提交于 2019-11-27 04:38:01
问题 is there a possibillity to get the filename e.g. xyz.com/blafoo/showall.html if you work with urllib or httplib? so that i can save the file under the filename on the server? if you go to sites like xyz.com/blafoo/ you cant see the filename. Thank you 回答1: To get filename from response http headers: import cgi response = urllib2.urlopen(URL) _, params = cgi.parse_header(response.headers.get('Content-Disposition', '')) filename = params['filename'] To get filename from the URL: import

Python-Requests close http connection

跟風遠走 提交于 2019-11-27 03:56:29
I was wondering, how do you close a connection with Requests (python-requests.org)? With httplib it's HTTPConnection.close() , but how do I do the same with Requests? Code is below: r = requests.post("https://stream.twitter.com/1/statuses/filter.json", data={'track':toTrack}, auth=('username', 'passwd')) for line in r.iter_lines(): if line: self.mongo['db'].tweets.insert(json.loads(line)) Thanks in advance. Felix Fung As discussed here , there really isn't such a thing as an HTTP connection and what httplib refers to as the HTTPConnection is really the underlying TCP connection which doesn't

Selenium headless browser webdriver [Errno 104] Connection reset by peer

喜欢而已 提交于 2019-11-27 03:29:57
问题 I am trying to scrape data from the URLs below. But selenium fails when driver.get(url) Some times the error is [Errno 104] Connection reset by peer , sometimes [Errno 111] Connection refused . On rare days it works just fine and on my mac with real browser the same spider works fine every single time. So this isn't related to my spider . Have tried many solutions like waiting got selectors on page, implicit wait, using selenium-requests yo pass proper request headers, etc. But nothing seems