请教一个关于post请求的问题,post视频文件到B站为什么转码失败?
想用python写一个上传B站视频的脚本,用cookie登录并从
http://member.bilibili.com/ge...
获取一些必要的参数,然后用
http://vs103.upload.acgvideo....
上传视频,最后把一些视频信息post到
http://member.bilibili.com/v/...
最后能把视频post到指定账号下但总是显示转码失败(正常上传能成功),如图:
代码如下:
import requests
import json
import sys
import os
import re
class User():
# some code
def cookies_login(self):
# cookie 登录
def password_login(self):
# 密码登录
def upload(self, filename):
# some code
try:
response = self.session.get('http://member.bilibili.com/get_vupload_url', cookies=cookies)
except:
print('Cannot get response from server!')
uploadresponse = json.loads(response.text)
"""
print(response.text)
{"url":"http://vs101.upload.acgvideo.com/upload.cgi?uid=43091594&filename=5896bf9e980e815d29a6b3b4d42d40cf&hash=7496003172e8a9a5bbe73beace2521ad",
"file_name":"5896bf9e980e815d29a6b3b4d42d40cf",
"server_ip":"2",
"html5":true}
"""
try: # if error happens...
uploadresponse["error_code"]
except KeyError:
pass
except:
print('ERROR: '+ uploadresponse['error_msg'] + ', ' + str(uploadresponse["error_code"]))
# http://member.bilibili.com/video_submit.html?tpl=upload
server_ip = str(uploadresponse['server_ip'])
remote_file_name = str(uploadresponse['file_name'])
upload_url = str(uploadresponse['url'])
# read file
with open(file_path, 'rb') as f:
files = {'file': f}
headers_post = {
'Accept-Language': 'zh-CN,zh;q=0.8',
'Access-Control-Request-Headers': 'content-range',
'Access-Control-Request-Method': 'POST',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding': 'gzip, deflate',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36',
'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryBVqq6OeVT3hluZUO',
'Connection': 'keep-alive',
}
self.session.options(upload_url, headers={'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate, sdch','Access-Control-Request-Method': 'POST'})
self.session.post(upload_url, files=files, headers = headers_post, stream=True)
print("upload success!")
from_data = {
'copyright': '1',
'cover': '',
'body': '[vupload]' + remote_file_name + ';' + filename + ';' + server_ip + ';[/vupload]',
'title': filename[:-4],
'typeid': '17',
'tags': 'youtube',
'keywords_change': '1',
'description': 'Top_10_Real_Time_Strategy_Games title',
'mission_id': '0',
}
resp = self.session.post('http://member.bilibili.com/v/archive/submit', headers={
'Accept':'application/json, text/javascript, */*; q=0.01',
'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
'Origin':'http://member.bilibili.com',
'Referer':'http://member.bilibili.com/v/video/submit.html',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36',
'X-Requested-With':'XMLHttpRequest',}, data=from_data)
print(resp.text)
print("hope success!")
if __name__ == "__main__":
up = User('***','***')
up.start()
up.upload("***")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
先传个小的视频,看能不能成功~