Skip to content

Commit c3282d2

Browse files
authored
fix: Fix broken example in Python 3.10 (#117)
1 parent 937cd32 commit c3282d2

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

examples/download_files.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async def download_files(queue, args):
4545
queue.task_done()
4646

4747

48-
def main():
48+
async def main():
4949

5050
parser = argparse.ArgumentParser(
5151
description=program_description)
@@ -77,21 +77,19 @@ def main():
7777
else:
7878
input_file = sys.stdin
7979

80-
loop = asyncio.get_event_loop()
81-
queue = asyncio.Queue(loop=loop)
82-
loop.create_task(read_hashes(queue, input_file))
80+
queue = asyncio.Queue()
81+
asyncio.create_task(read_hashes(queue, input_file))
8382

8483
worker_tasks = []
8584
for _ in range(args.workers):
8685
worker_tasks.append(
87-
loop.create_task(download_files(queue, args)))
86+
asyncio.create_task(download_files(queue, args)))
8887

8988
# Wait until all worker tasks has completed.
90-
loop.run_until_complete(asyncio.gather(*worker_tasks))
91-
loop.close()
89+
await asyncio.gather(*worker_tasks)
9290
if input_file != sys.stdin:
9391
input_file.close()
9492

9593

9694
if __name__ == '__main__':
97-
main()
95+
asyncio.run(main())

vt/client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ def _get_session(self):
233233
headers = {
234234
'X-Apikey': self._apikey,
235235
'Accept-Encoding': 'gzip',
236-
'Content-Type': 'application/json',
237236
'User-Agent': _USER_AGENT_FMT.format_map({
238237
'agent': self._agent, 'version': __version__})
239238
}
@@ -577,6 +576,11 @@ def patch_object(self, path, *path_args, obj):
577576
async def patch_object_async(self, path, *path_args, obj):
578577
"""Like :func:`patch_object` but returns a coroutine."""
579578
data = json.dumps({'data': obj.to_dict(modified_attributes_only=True)})
579+
580+
if self._user_headers is None:
581+
self._user_headers = {}
582+
self._user_headers['Content-Type'] = 'application/json'
583+
580584
response = await self.patch_async(path, *path_args, data=data)
581585
return await self._response_to_object(response)
582586

@@ -624,6 +628,11 @@ def post_object(self, path, *path_args, obj):
624628
async def post_object_async(self, path, *path_args, obj):
625629
"""Like :func:`post_object` but returns a coroutine."""
626630
data = json.dumps({'data': obj.to_dict()})
631+
632+
if self._user_headers is None:
633+
self._user_headers = {}
634+
self._user_headers['Content-Type'] = 'application/json'
635+
627636
response = await self.post_async(path, *path_args, data=data)
628637
return await self._response_to_object(response)
629638

0 commit comments

Comments
 (0)