我有视频450MB。我想将其上传到xvideos.com我在我的脚本中使用上传大文件太慢
xvideos_log_data = {'login': xv_login,
'password': password,
'referer': 'http://upload.xvideos.com/account',
'log': 'Login to your account'}
def xvideos(f_path):
_print('xvideos started uploading...')
try:
s = requests.Session()
s.post('http://upload.xvideos.com/account', data=xvideos_log_data, headers=headers)
rp = s.get('http://upload.xvideos.com/account/uploads/new')
apc = re.search(r'onclick="launch_upload_basic\(\'(.*?)\'\)', rp.text).group(1)
payload = {'APC_UPLOAD_PROGRESS': apc,
'message': ''}
r = s.post('http://upload.xvideos.com/account/uploads/submit?video_type=other',
data=payload,
files={'upload_file': open(f_path, 'rb')}, headers=headers)
edt = re.search(r'<a href="(.*?)" target="_top"', r.text)
if edt is None:
_print(re.search(r'inlineError.*>(.*?)<', r.text).group(1))
return
payload = {'title': make_title(),
'keywords': ' '.join(make_tags()),
'description': choice(description),
'hide': 0,
'update_video_information': 'Update information'}
r = s.post('http://upload.xvideos.com' + edt.group(1), data=payload, headers=headers)
_print('xvideos finished uploading')
except Exception as error:
_print(error)
finally:
return
问题是上传速度很慢,但成功。我在我的服务器上启动脚本。当我尝试在浏览器中上传时 - 速度很快。
可能是什么问题?
其实,你很可能通过简单的加载/ mmaping整个文件一次,并把它当作数据,而不是通过把事情快为你的用例,如果你有一个64位Python和足够的内存文件参数。 (因为你可能会避免使用这种缓慢的分块编码)。 – schlenk
我在ubuntu 12.10 x64服务器上有1GB RAM。我会尝试这些想法。谢谢。 – Alex