1

これを使用する場合、単純なアップロードアプリを作成しようとしています

files = {'upfile_0': (open('mplayer.exe', 'rb'))}
fin = r.post(action, files=files)

動作しますが、ファイル全体が RAM にあります。

ストリーミングアップロードに関するリクエストドキュメントを読んだ後。やってみたかった…

with open('mplayer.exe') as f:
    requests.post(action, data=f)

しかし、私はこのエラーが発生します。助けてくれてありがとう。

Traceback (most recent call last):
File "C:\Users\pulpe\Projekty\ulozto.py", line 23, in <module> requests.post(action, data=f)
File "C:\Python33\lib\site-packages\requests\api.py", line 88, in post return request('post', url, data=data, **kwargs)
File "C:\Python33\lib\site-packages\requests\api.py", line 44, in request return session.request(method=method, url=url, **kwargs)
File "C:\Python33\lib\site-packages\requests\sessions.py", line 335, in request resp = self.send(prep, **send_kwargs)
File "C:\Python33\lib\site-packages\requests\sessions.py", line 438, in send r = adapter.send(request, **kwargs)
File "C:\Python33\lib\site-packages\requests\adapters.py", line 292, in send timeout=timeout
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 428, in urlopen body=body, headers=headers)
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 280, in _make_request conn.request(method, url, **httplib_request_kw)
File "C:\Python33\lib\http\client.py", line 1061, in request self._send_request(method, url, body, headers)
File "C:\Python33\lib\http\client.py", line 1099, in _send_request self.endheaders(body)
File "C:\Python33\lib\http\client.py", line 1057, in endheaders self._send_output(message_body)
File "C:\Python33\lib\http\client.py", line 906, in _send_output self.send(message_body)
File "C:\Python33\lib\http\client.py", line 863, in send datablock = data.read(blocksize)
File "C:\Python33\lib\encodings\cp1250.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 2: character maps to <undefined>

オープンで「rb」を使用する場合。

Traceback (most recent call last):
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 428, in urlopen body=body, headers=headers)
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 280, in _make_request conn.request(method, url, **httplib_request_kw)
File "C:\Python33\lib\http\client.py", line 1061, in request self._send_request(method, url, body, headers)
File "C:\Python33\lib\http\client.py", line 1099, in _send_request self.endheaders(body)
File "C:\Python33\lib\http\client.py", line 1057, in endheaders self._send_output(message_body)
File "C:\Python33\lib\http\client.py", line 906, in _send_output self.send(message_body)
File "C:\Python33\lib\http\client.py", line 868, in send self.sock.sendall(datablock)
ConnectionResetError: [WinError 10054] Stávající připojení bylo vynuceně ukončeno vzdáleným hostitelem

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Python33\lib\site-packages\requests\adapters.py", line 292, in sendtimeout=timeout
File "C:\Python33\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 474, in urlopen raise MaxRetryError(self, url, e)
requests.packages.urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='upload.uloz.to', port=80): Max retries exceeded with url: /upload?user_id=4179756&did=uloz-to&host=www.uloz.to&a=ca92c8242dce5806238751f24114367174cf797d&rk=ocjd5s5ehl&t=1375618794 (Caused by <class 'ConnectionResetError'>: [WinError 10054] Stávající připojení bylo vynuceně ukončeno vzdáleným hostitelem)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\pulpe\Projekty\ulozto.py", line 23, in <module> requests.post(action, data=f)
File "C:\Python33\lib\site-packages\requests\api.py", line 88, in post return request('post', url, data=data, **kwargs)
File "C:\Python33\lib\site-packages\requests\api.py", line 44, in request return session.request(method=method, url=url, **kwargs)
File "C:\Python33\lib\site-packages\requests\sessions.py", line 335, in request resp = self.send(prep, **send_kwargs)
File "C:\Python33\lib\site-packages\requests\sessions.py", line 438, in send r = adapter.send(request, **kwargs)
File "C:\Python33\lib\site-packages\requests\adapters.py", line 327, in send raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='upload.uloz.to', port=80): Max retries exceeded with url: /upload?user_id=4179756&did=uloz-to&host=www.uloz.to&a=ca92c8242dce5806238751f24114367174cf797d&rk=ocjd5s5ehl&t=1375618794 (Caused by <class 'ConnectionResetError'>: [WinError 10054] Stávající připojení bylo vynuceně ukončeno vzdáleným hostitelem)
4

0 に答える 0