diff options
| author | Rapptz <[email protected]> | 2019-03-18 07:54:36 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2019-03-18 07:54:36 -0400 |
| commit | 5e65ec978cf278fefcc5586e2df732bc7a8bed4e (patch) | |
| tree | 83ad80c9e486a83e725b39d1ad2b3a6e9f48a19b /discord/http.py | |
| parent | Minor typo fix. (diff) | |
| download | discord.py-5e65ec978cf278fefcc5586e2df732bc7a8bed4e.tar.xz discord.py-5e65ec978cf278fefcc5586e2df732bc7a8bed4e.zip | |
Take back ownership of files from aiohttp for retrying requests.
Fix #1809
Diffstat (limited to 'discord/http.py')
| -rw-r--r-- | discord/http.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/discord/http.py b/discord/http.py index 6032d104..7e34951f 100644 --- a/discord/http.py +++ b/discord/http.py @@ -105,7 +105,7 @@ class HTTPClient: if self._session.closed: self._session = aiohttp.ClientSession(connector=self.connector, loop=self.loop) - async def request(self, route, *, header_bypass_delay=None, **kwargs): + async def request(self, route, *, files=None, header_bypass_delay=None, **kwargs): bucket = route.bucket method = route.method url = route.url @@ -151,6 +151,10 @@ class HTTPClient: await lock.acquire() with MaybeUnlock(lock) as maybe_lock: for tries in range(5): + if files: + for f in files: + f.reset(seek=tries) + async with self._session.request(method, url, **kwargs) as r: log.debug('%s %s with %s has returned %s', method, url, kwargs.get('data'), r.status) @@ -334,13 +338,13 @@ class HTTPClient: form.add_field('payload_json', utils.to_json(payload)) if len(files) == 1: - fp = files[0] - form.add_field('file', fp[0], filename=fp[1], content_type='application/octet-stream') + file = files[0] + form.add_field('file', file.fp, filename=file.filename, content_type='application/octet-stream') else: - for index, (buffer, filename) in enumerate(files): - form.add_field('file%s' % index, buffer, filename=filename, content_type='application/octet-stream') + for index, file in enumerate(files): + form.add_field('file%s' % index, file.fp, filename=file.filename, content_type='application/octet-stream') - return self.request(r, data=form) + return self.request(r, data=form, files=files) async def ack_message(self, channel_id, message_id): r = Route('POST', '/channels/{channel_id}/messages/{message_id}/ack', channel_id=channel_id, message_id=message_id) |