querystring = {"_": "1111111"}
payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"_csrf\"\r\n\r\n{}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"ReportForm[url]\"; filename=\"{}\"\r\nContent-Type: application/pdf\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--".format(csrf_token,'/home/shenjianlin/test_pdf'+'/'+'麦肯锡中国银行业 CEO 季刊-2018 年冬季刊精简版-137 页.pdf')
header= {
'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
'Cookie': "u=400; PHPSESSID=dfc4ac95c5c485a49ec167febc0b2da6; _csrf=0226ebc29a0710864db49376b6c400a3895ce0dbfb7161dc3d08e5bc8d148386a%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22_csrf%22%3Bi%3A1%3Bs%3A32%3A%22aoSW7OAr9i2rwVb2H7Khty6qSimxBUMn%22%3B%7D",
'Cache-Control': "no-cache",
'Postman-Token': "64fd1e6e-e442-4161-b32e-110c6627ee23"
}
response = requests.request("POST", url, data=payload, headers=header, params=querystring)
print(response.text)
Traceback (most recent call last):
File "
upload_pdf.py", line 66, in <module>
up_load_pdf()
File "
upload_pdf.py", line 40, in up_load_pdf
response = requests.request("POST", url, data=payload, headers=header, params=querystring)
File "/usr/lib/python3.4/site-packages/requests/
api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3.4/site-packages/requests/
sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3.4/site-packages/requests/
sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3.4/site-packages/requests/
adapters.py", line 440, in send
timeout=timeout
File "/usr/lib/python3.4/site-packages/urllib3/
connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/usr/lib/python3.4/site-packages/urllib3/
connectionpool.py", line 357, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib64/python3.4/http/
client.py", line 1137, in request
self._send_request(method, url, body, headers)
File "/usr/lib64/python3.4/http/
client.py", line 1181, in _send_request
body = body.encode('iso-8859-1')
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 313-320: ordinal not in range(256)