httplib

Python urllib vs httplib?

删除回忆录丶 提交于 2019-12-17 17:26:30
问题 When would someone use httplib and when urllib? What are the differences? I think I ready urllib uses httplib, I am planning to make an app that will need to make http request and so far I only used httplib.HTTPConnection in python for requests, and reading about urllib I see I can use that for request too, so whats the benefit of one or the other? 回答1: urllib (particularly urllib2) handles many things by default or has appropriate libs to do so. For example, urllib2 will follow redirects

How to fix httplib.BadStatusLine exception?

自闭症网瘾萝莉.ら 提交于 2019-12-17 16:40:36
问题 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. 回答1: Try to have a look what your server actually returns! It probably isn't a valid HTTP response. You

How to fix httplib.BadStatusLine exception?

試著忘記壹切 提交于 2019-12-17 16:40:14
问题 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. 回答1: Try to have a look what your server actually returns! It probably isn't a valid HTTP response. You

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

五迷三道 提交于 2019-12-17 10:42:34
问题 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

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

狂风中的少年 提交于 2019-12-17 10:42:02
问题 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

Put this request with Python httplib

倾然丶 夕夏残阳落幕 提交于 2019-12-13 04:22:41
问题 I want to put a request to HDFS REST API. It works in the RESTClient. But it failed when i translate it to Python edition( python httplib). And i can't use this in Curl for some reason. Anybody know httplib put, can help me translate it to Python edition? Here is the RESTClient edition: method: PUT URL: http://www.somedomain.com:50070/webhdfs/v1/levi/4?op=CREATE 回答1: With Requests: import requests requests.put('http://www.somedomain.com:50070/webhdfs/v1/levi/4?op=CREATE') With httplib :

Correct way to return JSON response from POST request with web.py

最后都变了- 提交于 2019-12-12 04:06:14
问题 I have a web.py server. I handle post requests like this: class Endpoint(object): def POST(self): received_payload = web.data() # Do things with the payload (a JSON) --- I receive the payload correctly response = {"Response": "Good"} # I also tried returning the dictionary directly and building my own requests.Response object return json.dumps(response) I am able to correctly receive and process the payload I send to the server, but I do not receive the response. On the client side, I do this

How do I respond to a “CONNECT” method request in a proxy server using socket in python?

一个人想着一个人 提交于 2019-12-12 03:34:38
问题 I am currently programming a proxy server using httplib, and when I try to connect to HTTPS websites (such as facebook and google) my client sends me "CONNECT" requests that look like this: CONNECT www.google.co.il:443 HTTP/1.1\r\n User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0\r\n Proxy-Connection: keep-alive\r\n Connection: keep-alive\r\n Host: www.google.co.il:443\r\n \r\n I took a working proxy from the internet and put it on, then sniffed the network

Why can't I view updates to a label while making an HTTP request in Python

回眸只為那壹抹淺笑 提交于 2019-12-12 02:43:12
问题 I have this code : def on_btn_login_clicked(self, widget): email = self.log_email.get_text() passw = self.log_pass.get_text() self.lbl_status.set_text("Connecting ...") params = urllib.urlencode({'@log_email': email, '@log_pass': passw, '@action': 'login', '@module': 'user'}) headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"} conn = httplib.HTTPConnection("website.com") self.lbl_status.set_text("Logging in ...") conn.request("POST", "/ajax.php", params,

ApplicationError2 and ApplicationError5 when communicating with external api from AppEngine

走远了吗. 提交于 2019-12-11 08:41:28
问题 I have built an application on google app engine, in python27 to connect with another services API and in general everything works smoothly. Every now and then I get one of the following two errors (<class 'google.appengine.api.remote_socket._remote_socket.error'>, error('An error occured while connecting to the server: ApplicationError: 2 ',), <traceback object at 0x11949c10>) (<class 'httplib.HTTPException'>, HTTPException('ApplicationError: 5 ',), <traceback object at 0x113a5850>) The