python post上传图片问题
POST http://dfmapi.dfm.tech/exchangeApi/common/upload-photo/private HTTP/1.1accept: application/json
accept-language: zh_CN
authorization: token=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI1MjkyNzYiLCJqdGkiOiJiYmVmZWMzZDc5MjA0OTM0YTA4ZGJlYzA1ZWE3MThlYSIsImF1ZCI6IlVTRVIiLCJpYXQiOjE1OTQyOTA4NjQsImV4cCI6MTU5NTU4Njg2NH0.SOtYLgrTE4ZL0LbnJjpHl1xqViWGGfTWLT8VIxcxmFjJfCR_WMCUKOsi05JNsjTw91vK1_BXVQWp_xR-I2O3Ig
Content-Type: multipart/form-data; boundary=247cec9f-bdf4-4ec3-af65-c129e8e64a49
Content-Length: 130598
Host: dfmapi.dfm.tech
Connection: Keep-Alive
Accept-Encoding: gzip
User-Agent: okhttp/3.12.1
--247cec9f-bdf4-4ec3-af65-c129e8e64a49
content-disposition: form-data; name="file"; filename="image-a2b427bd-967d-49fd-8c54-8d3b2a0a27d3.jpg"
Content-Type: image/jpeg
Content-Length: 130358
以上是我想要通过python直接给服务器上传图片数据,在app里头抓取的数据包,但我不知道通过python该怎么写,百度了很久也没弄出来,状态码都是406,下面是我整个请求数据
import requests
import base64
#登录app获取参数
def Login(zhanghao,mima):
url = 'http://dfmapi.dfm.tech/exchangeApi/user/login'
account_password = 'account-no={},login-password={}'.format(zhanghao, mima)
headers = {
'authorization': account_password,
'accept': 'application/json',
'accept-language': 'zh_CN',
'Host': 'dfmapi.dfm.tech',
'Connection': 'Keep-Alive',
'Accept-Encoding': 'gzip',
'User-Agent': 'okhttp/3.12.1',
# 'If-Modified-Since': 'Thu, 09 Jul 2020 06:59:09 GMT'
}
res = requests.get(url=url,headers=headers).json()
Token = res['data']['token']
return Token
def upload_photo(token):
url = 'http://dfmapi.dfm.tech/exchangeApi/common/upload-photo/private'
token_data = 'token={}'.format(token)
headers = {
'accept': 'application / json',
'accept - language': 'zh_CN',
'authorization':token_data,
'Content - Type': 'multipart / form - data;boundary = 247cec9f-bdf4-4ec3-af65-c129e8e64a49',
'Content - Length': '130598',
'Host': 'dfmapi.dfm.tech',
'Connection': 'Keep - Alive',
'Accept - Encoding': 'gzip',
'User - Agent': 'okhttp / 3.12.1'
}
data = {
'content-disposition': 'form - data;name = "file";filename = "1.jpg"',
'Content - Type': 'image / jpeg',
'Content - Length': '130358'
}
res = requests.post(url=url,data=data,headers=headers)
print(res)
# return res.text
if __name__ == '__main__':
'''打开本地文件获取参数'''
with open('11.txt') as f:
for txt in f:
list_account = txt.strip().split('----')
list_password = txt.strip().split('----')
upload_photo(Login(list_account,list_password))
upload_photo函数中的上传部分不知道该怎么写了,麻烦大佬指点 需要账号密码跟踪一次,能提供账号和密码吗? suchocolate 发表于 2020-7-12 13:59
需要账号密码跟踪一次,能提供账号和密码吗?
可以,需要q或者v不,app也可以提供,我一时兴起想写但卡在这里 czh1303541051 发表于 2020-7-12 14:51
可以,需要q或者v不,app也可以提供,我一时兴起想写但卡在这里
pakopoo@163.com
1111qqqq czh1303541051 发表于 2020-7-12 14:53
1111qqqq
提示没有这个账号:
是这样,不同的网站,上传方式不同,需要登陆你上传图片的页面,然后用浏览器f12上传一次图片,看它上传时实际的上传方式。
suchocolate 发表于 2020-7-12 15:14
提示没有这个账号:
是这样,不同的网站,上传方式不同,需要登陆你上传图片的页面,然后用浏览器f12 ...
不是这个网站,post的请求我也百度看了好多了,但弄不出结果来,方便加我q说么,1 303541051
页:
[1]