我想上传图片,但代码会返回https://hizliresim.com。也就是说,它不会上传文件。
代码:
import requests
import re
s = requests.Session()
tokenadres = '<input name="_token" type="hidden" value="(.*?)">'
token = re.findall(tokenadres,s.get('https://hizliresim.com/').text)
print token[0]
files={'MAX_FILE_SIZE': (None, 0),
'_token': (None, token[0]),
'local_files[]': ('ss.png', open('C:/ss.png', 'rb'), 'image/png'),
'remote_file_url': (None, None),
'upload_setting_description': (None, None),
'upload_setting_is_public': (None, 1)}
response = s.post('https://hizliresim.com/p/yukle', data=files)
请求有效负载(在浏览器上):
------WebKitFormBoundaryE8nuwMyEFZ25OzGh
Content-Disposition: form-data; name="MAX_FILE_SIZE"
0
------WebKitFormBoundaryE8nuwMyEFZ25OzGh
Content-Disposition: form-data; name="_token"
QV1hXWr4lADl8hFotk3RD8sdvB9LUf8kbAcOuhPo
------WebKitFormBoundaryE8nuwMyEFZ25OzGh
Content-Disposition: form-data; name="local_files[]"; filename="ss11.png"
Content-Type: image/png
------WebKitFormBoundaryE8nuwMyEFZ25OzGh
Content-Disposition: form-data; name="remote_file_url"
------WebKitFormBoundaryE8nuwMyEFZ25OzGh
Content-Disposition: form-data; name="upload_setting_description"
------WebKitFormBoundaryE8nuwMyEFZ25OzGh
Content-Disposition: form-data; name="upload_setting_is_public"
1
------WebKitFormBoundaryE8nuwMyEFZ25OzGh--