Skip to content

Instantly share code, notes, and snippets.

@w1ndy
Created November 13, 2016 14:46
Show Gist options
  • Save w1ndy/7a328f9fcbb3879007cc63e1090a33e2 to your computer and use it in GitHub Desktop.
Save w1ndy/7a328f9fcbb3879007cc63e1090a33e2 to your computer and use it in GitHub Desktop.
Get voucher from Tencent Cloud
#!/usr/bin/python3
import requests
import json
requests.packages.urllib3.disable_warnings()
# Fill in {{variables}} below
COOKIE = '{{PASTE YOUR OWN COOKIE HERE}}'
REQUEST_URL = '/act/campus/ajax/index?uin={{QQ NUMBER}}&csrfCode={{CSRF CODE}}' # Get URL from Chrome inspector
MAX_RETRIES = 30
def main():
retries = MAX_RETRIES
while retries:
retries -= 1
print('[%d/%d] Attempting to get voucher...' % (MAX_RETRIES - retries, MAX_RETRIES))
r = requests.post('https://119.29.42.201%s' % REQUEST_URL, \
headers={ \
'Cookie': COOKIE, \
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.87 Safari/537.36', \
'Referer': 'https://www.qcloud.com/act/campus', \
'Origin': 'https://www.qcloud.com', \
'X-Requested-With': 'XMLHttpRequest' \
}, \
data={ \
'action': 'getVoucher' \
}, \
verify=False)
if r.status_code != 200:
print('request failed with %d' % r.status_code)
else:
result = json.loads(r.text)
if result['code'] == 10006:
print('no voucher available.')
else:
print('server returned %s: %s' % (str(result['code']), result['msg']))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment