Created
April 10, 2019 06:09
-
-
Save BobDu/57e19d0b008e67cb9d9344dd9da6edb3 to your computer and use it in GitHub Desktop.
mayi proxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
import time | |
import requests | |
import toml | |
from requests.packages.urllib3.exceptions import InsecureRequestWarning # pylint: disable=import-error | |
requests.packages.urllib3.disable_warnings(InsecureRequestWarning) # pylint: disable=no-member | |
cfg = toml.load('test.toml') | |
app_key = cfg.get('app-key') | |
app_secret = cfg.get('app-secret') | |
proxy_ip = cfg.get('proxy-ip') | |
proxy_port = cfg.get('proxy-port') | |
proxy_url = { | |
'http': 'http://' + proxy_ip + ':' + proxy_port, | |
'https': 'https://' + proxy_ip + ':' + proxy_port | |
} | |
url = 'https://httpbin.org/get' | |
def get_proxy_auth_header(): | |
parmas = { | |
'app_key': app_key, | |
'timestamp': time.strftime(r'%Y-%m-%d %H:%M:%S'), | |
'random-useragent': 'pc' | |
} | |
codes = app_secret | |
for k, v in sorted(parmas.items(), key=lambda x: x[0]): | |
codes += k + v | |
codes += app_secret | |
sign = hashlib.md5(codes.encode('utf-8')).hexdigest().upper() | |
proxy_auth_header = 'MYH-AUTH-MD5 sign=' + sign | |
for k, v in parmas.items(): | |
proxy_auth_header += '&' + k + '=' + v | |
return proxy_auth_header | |
resp = requests.get( | |
url, | |
headers={'Proxy-Authorization': get_proxy_auth_header()}, | |
proxies=proxy_url, | |
timeout=(300, 270), | |
verify=False) | |
# timeout tuple: (connect timeout, read timeout) | |
if(resp.status_code == 200): | |
print(resp.json()) | |
else: | |
print(resp.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment