我有視頻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