httplib

When I use python requests to check a site, if the site redirects me to another page, will I know?

不羁的心 提交于 2019-12-23 07:02:28
问题 What I mean is, if I go to "www.yahoo.com/thispage", and yahoo has set up a filter to redirect /thispage to /thatpage. So whenever someone goes to /thispage, s/he will land on /thatpage. If I use httplib/requests/urllib, will it know that there was a redirection? What error pages? Some sites redirect user to /errorpage whenever the page cannot be found. 回答1: With requests , you get a listing of any redirects in the .history attribute of the response object. It returns a Python list. See the

Python JSON POST request

我只是一个虾纸丫 提交于 2019-12-23 04:45:37
问题 Different questions re: 1 script. I have to JSON-ify from a Python script that'll run on client-side and do a POST on a remote URL. I am following the docs here http://docs.python.org/2/library/httplib.html - However, I am not sure if I am doing it right. I am not getting any response-status either when I run it on my Mac. Right now, I have doubts about the following - (1) The dummy 'device_key' (of the client) (2) The IP, Port listed at HTTPConnection --- I don't want to hard-code the IP,

Exchange Web Services (EWS) - Exchange 2010 soap calls via suds

风流意气都作罢 提交于 2019-12-22 11:32:57
问题 Im trying to send an email via Exchange Web Services using suds 0.4.1: import suds from suds.client import Client from suds.transport.https import WindowsHttpAuthenticated url = "file:///C:/Services.wsdl" user = 'domain\\user' password = "hardtoguess" ntlm = WindowsHttpAuthenticated(username=user,password=password) c = Client(url, transport=ntlm) xml = ''' <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=

Reading CONNECT headers

旧巷老猫 提交于 2019-12-21 21:28:09
问题 I'm using a proxy service (proxymesh) that puts useful information into the headers sent in response to a CONNECT request. For whatever reason, Python's httplib doesn't parse them: > CONNECT example.com:443 HTTP/1.1 > Host: example.com:443 > < HTTP/1.1 200 Connection established < X-Useful-Header: value # completely ignored < The requests module uses httplib internally, so it ignores them as well. How do I extract headers from a CONNECT request? 回答1: Python's httplib actually ignores these

How do I post non-ASCII characters using httplib when content-type is “application/xml”

心已入冬 提交于 2019-12-19 17:47:57
问题 I've implemented a Pivotal Tracker API module in Python 2.7. The Pivotal Tracker API expects POST data to be an XML document and "application/xml" to be the content type. My code uses urlib/httplib to post the document as shown: request = urllib2.Request(self.url, xml_request.toxml('utf-8') if xml_request else None, self.headers) obj = parse_xml(self.opener.open(request)) This yields an exception when the XML text contains non-ASCII characters: File "/usr/lib/python2.7/httplib.py", line 951,

How do I post non-ASCII characters using httplib when content-type is “application/xml”

折月煮酒 提交于 2019-12-19 17:47:12
问题 I've implemented a Pivotal Tracker API module in Python 2.7. The Pivotal Tracker API expects POST data to be an XML document and "application/xml" to be the content type. My code uses urlib/httplib to post the document as shown: request = urllib2.Request(self.url, xml_request.toxml('utf-8') if xml_request else None, self.headers) obj = parse_xml(self.opener.open(request)) This yields an exception when the XML text contains non-ASCII characters: File "/usr/lib/python2.7/httplib.py", line 951,

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

随声附和 提交于 2019-12-19 09:53:55
问题 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",

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

戏子无情 提交于 2019-12-19 09:52:54
问题 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",

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

白昼怎懂夜的黑 提交于 2019-12-19 03:22:59
问题 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

Suds Error: BadStatusLine in httplib

孤街浪徒 提交于 2019-12-18 02:58:18
问题 I am using suds 0.3.6. When creating a suds client, I randomly get an error: httplib.py, _read_status(), line 355, class httplib.BadStatusLine' Here is the code used to create the client: imp = Import('http://www.w3.org/2001/XMLSchema') imp.filter.add('http://tempuri.org/encodedTypes') imp.filter.add('http://tempuri.org/') self.doctor = ImportDoctor(imp) self.client = Client(self.URL,doctor=self.doctor) What does this error mean and how can I fix it? Thanks! 回答1: That means there is a problem