English 中文(简体)
甲型六氯环己烷 HTTP Proxy> HTTPS 请求
原标题:Python urllib2 > HTTP Proxy > HTTPS request

工作罚款:

import urllib2

opener = urllib2.build_opener(
                urllib2.HTTPHandler(),
                urllib2.HTTPSHandler(),
                urllib2.ProxyHandler({ http :  http://user:pass@proxy:3128 }))
urllib2.install_opener(opener)
print urllib2.urlopen( http://www.google.com ).read()

但是,如果是<> 改为:

...
print urllib2.urlopen( https://www.google.com ).read()

存在错误:

Traceback (most recent call last):
  File "D:Temp6	mp.py", line 13, in <module>
    print urllib2.urlopen( https://www.google.com ).read()
  File "C:Python26liburllib2.py", line 124, in urlopen
    return _opener.open(url, data, timeout)
  File "C:Python26liburllib2.py", line 389, in open
    response = self._open(req, data)
  File "C:Python26liburllib2.py", line 407, in _open
     _open , req)
  File "C:Python26liburllib2.py", line 367, in _call_chain
    result = func(*args)
  File "C:Python26liburllib2.py", line 1154, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "C:Python26liburllib2.py", line 1121, in do_open
    raise URLError(err)
URLError: <urlopen error [Errno 10060]

为什么以及如何解决这一问题?

问题回答

改变这一思路:

urllib2.ProxyHandler({ http :  http://user:pass@proxy:3128 }))

为此:

urllib2.ProxyHandler({ https :  http://user:pass@proxy:3128 }))

它对我课以罚款。

documentation lli2说:

Note: Currently urllib2 does not support fetching of https locations through a proxy. However, this can be enabled by extending urllib2 as shown in this recipe.

我必须承认,就Jython 2.5.3而言,我 work不工作,但我仍在尝试。

,p至Jython 2.5.3,为我工作。 我现在可以把HTTPS的资源压在代理服务器上。

www.un.org/Depts/DGACM/index_spanish.htm 这里的守则是,向HTTPS资源提供吉大港山区基本认证(DON T FORGET TO INSTALL PATCHIRST(见前次更新)):

from suds.client import Client
from suds.transport.https import HttpAuthenticated

credentials = dict(username= ... , password= ... , proxy={ https :  host:port ,  http :  host:port })
t = HttpAuthenticated(**credentials)
url =  https://example.com/service?wsdl 
client = Client(url, transport=t)
print client.service.getFoo()




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签