httplib

A socket operation was attempted to an unreachable network in python httplib

核能气质少年 提交于 2019-12-01 11:34:41
I am trying to make a REST client from django using httplib . But it is refusing the connection I tried the following import hashlib import hmac from django.shortcuts import render_to_response from django.template import RequestContext def loginAction(request): username=request.POST['email'] password=request.POST['password'] import httplib, urllib params = urllib.urlencode({'username': username}) #hash username here to authenticate digest=hmac.new("qnscAdgRlkIhAUPY44oiexBKtQbGY0orf7OV1I50", str(request.POST['password']),hashlib.sha1).hexdigest() auth=username+":"+digest headers = {"Content

How to “keep-alive” with cookielib and httplib in python?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 16:36:52
In python, I'm using httplib because it "keep-alive" the http connection (as oppose to urllib(2)). Now, I want to use cookielib with httplib but they seem to hate each other!! (no way to interface them together). Does anyone know of a solution to that problem? HTTP handler for urllib2 that supports keep-alive Serge Broslavsky You should consider using the Requests library instead at the earliest chance you have to refactor your code. In the mean time; HACK ALERT! :) I'd go other suggested way, but I've done a hack (done for different reasons though), which does create an interface between

Selenium 2.53.5 httplib.BadStatusLine: '' Python

折月煮酒 提交于 2019-11-30 16:36:07
Im trying to automate the registration of serial numbers in an online form using Selenium 2.53.5 in Python 2.7. The script has been working for 2+ months, but yesterday I started receiving an error right when I go to run it: httplib.BadStatusLine: ''. Is there any known fix for this? I've read that leading/trailing new line characters can mess up the retrieving of the url but I can't seem to identify the issue. Code: import sys import time from selenium import webdriver from selenium.webdriver.chrome.options import Options class SerialSet: def __init__(self, fileName, driverPath, user,

Python urllib2 cannot open localhost on alternate port (not 80)? Error 10013

孤街浪徒 提交于 2019-11-30 16:12:22
Here is my server.py : import BaseHTTPServer import SocketServer class TestRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(self): self.wfile.write("hello world at %s" % __file__) server = BaseHTTPServer.HTTPServer(('', 10000), TestRequestHandler) #server = SocketServer.ThreadingTCPServer(('', 8888), TestRequestHandler) server.serve_forever() Here is my client.py : import urllib2 req = urllib2.Request('http://127.0.0.1:10000/') handle = urllib2.urlopen(req) content = handle.read() Then I start server.py, it works. When I start client.py, I get this error on Windows 7, Python 2

Python urllib2 cannot open localhost on alternate port (not 80)? Error 10013

不想你离开。 提交于 2019-11-30 16:00:34
问题 Here is my server.py : import BaseHTTPServer import SocketServer class TestRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(self): self.wfile.write("hello world at %s" % __file__) server = BaseHTTPServer.HTTPServer(('', 10000), TestRequestHandler) #server = SocketServer.ThreadingTCPServer(('', 8888), TestRequestHandler) server.serve_forever() Here is my client.py : import urllib2 req = urllib2.Request('http://127.0.0.1:10000/') handle = urllib2.urlopen(req) content = handle

Error using httlib's HTTPSConnection with PKCS#12 certificate

一笑奈何 提交于 2019-11-30 09:21:05
问题 I'm trying to use httplib's HTTPSConnection for client validation, using a PKCS #12 certificate. I know the certificate is good, as I can connect to the server using it in MSIE and Firefox. Here's my connect function (the certificate includes the private key). I've pared it down to just the basics: def connect(self, cert_file, host, usrname, passwd): self.cert_file = cert_file self.host = host self.conn = httplib.HTTPSConnection(host=self.host, port=self.port, key_file=cert_file, cert_file

HTTPConnection.request not respecting timeout?

时光总嘲笑我的痴心妄想 提交于 2019-11-30 07:39:11
问题 I'm trying to use HTTPConnection (2.7.8) to make a request and I've set the timeout to 10 with HTTPConnection(host, timeout=10) . However, HTTPConnection.request() doesn't seem to timeout after 10 seconds. In fact, HTTPConnection.timeout doesn't even seem to be read by HTTPConnection.request() (it's only read by HTTPConnection.connect() . Is my understanding correct? Is timeout only applicable to connect() and not request() ? Is there a way to timeout request() ? Update: I think I've narrowed

How to “keep-alive” with cookielib and httplib in python?

空扰寡人 提交于 2019-11-29 23:54:36
问题 In python, I'm using httplib because it "keep-alive" the http connection (as oppose to urllib(2)). Now, I want to use cookielib with httplib but they seem to hate each other!! (no way to interface them together). Does anyone know of a solution to that problem? 回答1: HTTP handler for urllib2 that supports keep-alive 回答2: You should consider using the Requests library instead at the earliest chance you have to refactor your code. In the mean time; HACK ALERT! :) I'd go other suggested way, but I

Selenium 2.53.5 httplib.BadStatusLine: '' Python

☆樱花仙子☆ 提交于 2019-11-29 23:33:08
问题 Im trying to automate the registration of serial numbers in an online form using Selenium 2.53.5 in Python 2.7. The script has been working for 2+ months, but yesterday I started receiving an error right when I go to run it: httplib.BadStatusLine: ''. Is there any known fix for this? I've read that leading/trailing new line characters can mess up the retrieving of the url but I can't seem to identify the issue. Code: import sys import time from selenium import webdriver from selenium

How do I have python httplib accept untrusted certs?

南笙酒味 提交于 2019-11-29 09:12:52
How do I have python httplib accept untrusted certs? I created a snake oil/self signed cert on my webserver, and my python client fails to connect as I am using a untrusted cert. I'd rather problematically fix this in my client code rather than have it trusted on my system. import httplib def main(): conn = httplib.HTTPSConnection("127.0.0.1:443") conn.request("HEAD","/") res = conn.getresponse() print res.status, res.reason data = res.read() print len(data) if __name__ == "__main__": main() Some of my scripts stopped working after updating my computer. Turns out, this was the problem: https:/