|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- POST http://dfmapi.dfm.tech/exchangeApi/common/upload-photo/private HTTP/1.1
- accept: 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('----')[0]
- list_password = txt.strip().split('----')[1]
- upload_photo(Login(list_account,list_password))
复制代码
upload_photo函数中的上传部分不知道该怎么写了,麻烦大佬指点 |
|