上传一般都是要带上登录信息的,加上cookie
import urllib3
import requests
from requests.cookies import RequestsCookieJar
def do_upload():
url = 'http://XXXXX'
filepath = 'E:/18156JsDBproxyold_1.jpg'
cookie_jar = RequestsCookieJar()
cookie_jar.set('JSESSIONID', '0000zgdUT0kisG9gSU62Nbm10etfn')
file = ('18156JsDBproxyold_1.jpg', open(filepath, 'rb').read())
data = {
'file': file
}
encode_data = urllib3.encode_multipart_formdata(data)
content_type = encode_data[1]
# 请求头视情况而定
headers = {
'Accept': 'text/html, application/xhtml+xml, image/jxr, */*',
'Accept-Encoding': 'gzip,deflate',
'Accept-Language': 'zh-CN',
'Content-Type': content_type,
}
reponse = requests.post(url, headers=headers, data=encode_data[0], cookies=cookie_jar)
print(reponse.text)
def do_upload():
url = 'http://XXXXX'
filepath = 'E:/18156JsDBproxyold_1.jpg'
cookie_jar = RequestsCookieJar()
cookie_jar.set('JSESSIONID', '0000zgdUT0kisG9gSU62Nbm10etfn')
# 注意这里不需要read,可以取看看源码
file = ('18156JsDBproxyold_1.jpg', open(filepath, 'rb'))
files= {
'file': file
}
data={
'filetype':'beautful'
}
# 请求头视情况而定
headers = {
'Accept': 'text/html, application/xhtml+xml, image/jxr, */*',
'Accept-Encoding': 'gzip,deflate',
'Accept-Language': 'zh-CN'
}
reponse = requests.post(url, headers=headers, data=data,files=files, cookies=cookie_jar)
print(reponse.text)