Python HTTPS client with basic proxy authentication

From Python, I would like to get content from a website via HTTPS with basic authentication. I need content on disk. I am on an intranet trusting an HTTPS server. Python 2.6.2 platform for Windows.

I played with urllib2 but failed so far.

I have a solution calling wget via os.system ():

wget_cmd = r'\path\to\wget.exe -q -e "https_proxy = http://fqdn.to.proxy:port" --no-check-certificate --http-user="username" --http-password="password" -O path\to\output https://fqdn.to.site/content'

I would like to get rid of os.system (). Is this possible in Python?

+3
source share
3 answers

Proxies and https did not work for a long time with urllib2. It will be fixed in the next released version of python 2.6 (v2.6.3).

, mercurial: http://hg.intevation.org/mercurial/crew/rev/59acb9c7d90f

+3

( , ):

import urllib2
authinfo = urllib2.HTTPBasicAuthHandler()
authinfo.add_password(realm='Fill In Realm Here',
                      uri='https://fqdn.to.site/content',
                      user='username',
                      passwd='password')
proxy_support = urllib2.ProxyHandler({"https" : "http://fqdn.to.proxy:port"})
opener = urllib2.build_opener(proxy_support, authinfo)
fp = opener.open("https://fqdn.to.site/content")
open(r"path\to\output", "wb").write(fp.read())
+3

You can also try:   http://code.google.com/p/python-httpclient/

(It also supports server certificate verification.)

0
source

Source: https://habr.com/ru/post/1718154/


All Articles