Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import pycurl
- from urllib.parse import urlencode
- from io import BytesIO
- buff = BytesIO()
- boundary = ''
- abc = 'qeertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'
- for b in range(16):
- boundary += random.choice(abc)
- mime_type = "multipart/form-data; boundary=----WebKitFormBoundary" + boundary
- text = """------WebKitFormBoundary%srnContent-Disposition: form-data; name="imgfile";
- filename="test.png"rnContent-Type: image/pngrnrnrn------WebKitFormBoundary%s--rn""" % (boundary, boundary)
- content_type = 'multipart/form-data; boundary=----WebKitFormBoundary' + boundary
- post_data = urlencode({"mimeType": mime_type, "text": text})
- headers = {
- 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 '
- 'YaBrowser/17.6.1.776 (beta) Yowser/2.5 Safari/537.36',
- 'referer': 'https://s.taobao.com/search?initiative_id=staobaoz_20170719&q=',
- 'origin': 'https://s.taobao.com',
- 'Expect': '',
- 'accept': 'application/json, text/javascript, */*; q=0.01',
- ':scheme': 'https',
- ':path': '/image',
- ':method': 'POST',
- ':authority': 's.taobao.com',
- 'x-requested-with': 'XMLHttpRequest',
- 'accept-language': 'ru,en;q=0.8',
- 'content-type': content_type,
- }
- headers_list = ["%s: %s" % (n, v) for n, v in headers.items()]
- response_headers = []
- def header_function(header_line):
- header_line = header_line.decode('iso-8859-1')
- response_headers.append(header_line)
- c = pycurl.Curl()
- c.setopt(c.URL, 'https://s.taobao.com/image')
- c.setopt(c.WRITEDATA, buff)
- c.setopt(c.FOLLOWLOCATION, True)
- c.setopt(c.VERBOSE, True)
- c.setopt(c.POSTFIELDS, post_data)
- c.setopt(c.HTTPHEADER, headers_list)
- c.setopt(c.HEADERFUNCTION, header_function)
- c.setopt(c.HTTPPOST, [
- ('file', (
- c.FORM_FILE, 'test.png',
- c.FORM_FILENAME, 'test.png',
- c.FORM_CONTENTTYPE, 'image/png'
- ))
- ])
- c.perform()
- body = buff.getvalue()
- print(body.decode())
- print(c.getinfo(c.EFFECTIVE_URL))
- c.close()
- {"status":0,"error":true,"errorCode":"509","errorMsg":"请重新上传试试","extraInfo":""}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement