11
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

python urllib3 を使った通信で認証プロキシを通す

Posted at

python の urllib3 を使ってプロキシ認証を通す。

proxy_test.py
# コロン区切りでユーザID、パスワードを設定 userid:password
PROXY_BASIC_AUTH = "userid:password"

# プロキシのURL, port
PROXY_URL = "http://proxy.net:8080"

# 接続先 URL
REQUEST_URL = "https://www.djangoproject.com/"

if __name__ == '__main__':

   headers = urllib3.util.make_headers(proxy_basic_auth=PROXY_BASIC_AUTH)
   http = urllib3.ProxyManager(proxy_url=PROXY_URL,
           proxy_headers=headers, cert_reqs='CERT_REQUIRED', ca_certs=certifi.where())
   r = http.request("GET", REQUEST_URL)

   # 出力
   print(r.data, r.status, )
11
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?