python urllib socks5 auth username password 設定
在使用一批socks5帶使用者名稱和密碼的代理的時候需要用到urllib這個python庫
# https://pypi.org/project/PySocks/
import urllib
import socks
import socket
# from urllib import request
from urllib.error import URLError
username = "username"
password = "password"
ip = "107.*.*.122"
port = 11336
proxy = "socks5://{username}:{password}@{ip}:{port}".format(username=username,password=password,ip=ip,port=port)
socks.set_default_proxy(socks.SOCKS5, ip, port,username=username,password=password)
socket.socket = socks.socksocket
url = 'http://httpbin.org/get'
try:
req = urllib.request.Request(url=url,headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'})
response = urllib.request.urlopen(req)
# response = request.urlopen(url)
print(response.read().decode('utf-8'))
except URLError as e:
print(e)
// 相應結果
{
"args": {},
"headers": {
"Accept-Encoding": "identity",
"Host": "httpbin.org",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
"X-Amzn-Trace-Id": "Root=1-5fd8a0d5-6f4cb76331f614657da833e8"
},
"origin": "107.*.*.122",
"url": "http://httpbin.org/get"
}
參考:https://pypi.org/project/PySocks/
相關文章
- 解決安裝Redis之後設定密碼,報(error) ERR Client sent AUTH, but no password is setRedis密碼Errorclient
- sqlplus / as sysdba報錯ORA-01017: invalid username/password; logon deniedSQLGo
- 【YashanDB資料庫】YAS-02143 invalid username/password, login denied資料庫
- Python3 urllib 與 Python2 urllib的變化Python
- Python中urllib和urllib2庫的用法Python
- laravel 使用 auth:admin 中介軟體後, 會把 Auth->defaultDriver 設定為 adminLaravel
- SourceTreet提交時顯示remote: Incorrect username or password ( access token )(4種解決辦法)REM
- Python urllib HTTP頭注入漏洞PythonHTTP
- python urllib 基礎之 3Python
- python urllib 基礎 get ajaxPython
- Python 爬蟲十六式 - 第二式: urllib 與 urllib3Python爬蟲
- 學習Python的urllib模組Python
- Python模組之urllib模組Python
- python爬蟲基礎之urllibPython爬蟲
- laravel8.5用自帶的auth登入功能,預設驗證的password密碼欄位,怎麼修改Laravel密碼
- python爬蟲常用庫之urllib詳解Python爬蟲
- URL username 屬性
- python3:巧用adb命令獲得PC username和devicelistPythondev
- MASA Auth - SSO與Identity設計IDE
- python urllib.parse urlparse path url路徑分割Python
- urllib庫
- python 設定背景影像Python
- python flask 設定cookiePythonFlaskCookie
- 【Lintcode】1789. Distinguish UsernameNGUI
- auth
- 【Python】用原生的urllib2+httplib請求HttpsPythonHTTP
- java如何實現python的urllib.quote(str,safe='/')JavaPython
- JB的Python之旅-爬蟲篇--urllib和Beautiful SoupPython爬蟲
- Python爬蟲進階之urllib庫使用方法Python爬蟲
- Auth、OAuth 和 Auth 什麼是?OAuth
- Python怎麼設定代理Python
- python3:urllib.request 的主要函式說明Python函式
- SOCKS5
- Python requests設定代理的方法Python
- python-docx 頁面設定Python
- Django中的函式make_password、set_password和check_passwordDjango函式
- Python自動化測試 :urllib2 傳送HTTP RequestPythonHTTP
- python urllib2中文亂碼怎麼解決Python