Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. import random
  2. import pycurl
  3. from urllib.parse import urlencode
  4. from io import BytesIO
  5.  
  6. buff = BytesIO()
  7.  
  8. boundary = ''
  9. abc = 'qeertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'
  10. for b in range(16):
  11. boundary += random.choice(abc)
  12.  
  13. mime_type = "multipart/form-data; boundary=----WebKitFormBoundary" + boundary
  14. text = """------WebKitFormBoundary%srnContent-Disposition: form-data; name="imgfile";
  15. filename="test.png"rnContent-Type: image/pngrnrnrn------WebKitFormBoundary%s--rn""" % (boundary, boundary)
  16. content_type = 'multipart/form-data; boundary=----WebKitFormBoundary' + boundary
  17. post_data = urlencode({"mimeType": mime_type, "text": text})
  18.  
  19. headers = {
  20. 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 '
  21. 'YaBrowser/17.6.1.776 (beta) Yowser/2.5 Safari/537.36',
  22. 'referer': 'https://s.taobao.com/search?initiative_id=staobaoz_20170719&q=',
  23. 'origin': 'https://s.taobao.com',
  24. 'Expect': '',
  25. 'accept': 'application/json, text/javascript, */*; q=0.01',
  26. ':scheme': 'https',
  27. ':path': '/image',
  28. ':method': 'POST',
  29. ':authority': 's.taobao.com',
  30. 'x-requested-with': 'XMLHttpRequest',
  31. 'accept-language': 'ru,en;q=0.8',
  32. 'content-type': content_type,
  33. }
  34. headers_list = ["%s: %s" % (n, v) for n, v in headers.items()]
  35. response_headers = []
  36.  
  37.  
  38. def header_function(header_line):
  39. header_line = header_line.decode('iso-8859-1')
  40. response_headers.append(header_line)
  41.  
  42. c = pycurl.Curl()
  43. c.setopt(c.URL, 'https://s.taobao.com/image')
  44. c.setopt(c.WRITEDATA, buff)
  45. c.setopt(c.FOLLOWLOCATION, True)
  46. c.setopt(c.VERBOSE, True)
  47. c.setopt(c.POSTFIELDS, post_data)
  48. c.setopt(c.HTTPHEADER, headers_list)
  49. c.setopt(c.HEADERFUNCTION, header_function)
  50. c.setopt(c.HTTPPOST, [
  51. ('file', (
  52. c.FORM_FILE, 'test.png',
  53. c.FORM_FILENAME, 'test.png',
  54. c.FORM_CONTENTTYPE, 'image/png'
  55. ))
  56. ])
  57.  
  58. c.perform()
  59. body = buff.getvalue()
  60. print(body.decode())
  61. print(c.getinfo(c.EFFECTIVE_URL))
  62. c.close()
  63.  
  64. {"status":0,"error":true,"errorCode":"509","errorMsg":"请重新上传试试","extraInfo":""}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement