Skip to content

Commit 861fd14

Browse files
author
Hamel Husain
authored
Merge pull request #308 from pradeepbbl/issue/304-fix-archive-dowload
fix #304 UnicodeDecodeError while downloading git archive
2 parents f95cd74 + 688e4df commit 861fd14

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

fastcore/net.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ def urlsend(url, verb, headers=None, route=None, query=None, data=None, json_dat
172172
"Send request with `urlrequest`, converting result to json if `return_json`"
173173
req = urlrequest(url, verb, headers, route=route, query=query, data=data, json_data=json_data)
174174
if debug: debug(req)
175+
176+
if route and route.get('archive_format', None):
177+
return urlread(req, decode=False, return_json=False, return_headers=return_headers)
178+
175179
return urlread(req, return_json=return_json, return_headers=return_headers)
176180

177181
# Cell

nbs/03b_net.ipynb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,43 @@
490490
" \"Send request with `urlrequest`, converting result to json if `return_json`\"\n",
491491
" req = urlrequest(url, verb, headers, route=route, query=query, data=data, json_data=json_data)\n",
492492
" if debug: debug(req)\n",
493+
" \n",
494+
" if route and route.get('archive_format', None):\n",
495+
" return urlread(req, decode=False, return_json=False, return_headers=return_headers)\n",
496+
" \n",
493497
" return urlread(req, return_json=return_json, return_headers=return_headers)"
494498
]
495499
},
500+
{
501+
"cell_type": "markdown",
502+
"metadata": {},
503+
"source": [
504+
"Test [ghapi.actions.download_artifact](https://docs.github.com/rest/reference/actions#download-an-artifact)"
505+
]
506+
},
507+
{
508+
"cell_type": "code",
509+
"execution_count": null,
510+
"metadata": {},
511+
"outputs": [],
512+
"source": [
513+
"\n",
514+
"url = \"https://github.com/fastai/ghapi/archive/refs/tags/0.1.15.zip\"\n",
515+
"header={'Accept': 'application/vnd.github.v3+json'}\n",
516+
"route={'artifact_id': 1234, 'archive_format': 'zip'} \n",
517+
"\n",
518+
"res = urlsend(url, \"get\", headers=header, route=route)\n",
519+
"assert type(res) is bytes\n",
520+
"\n",
521+
"def _org_urlsend(url, verb, headers=None, route=None, query=None, data=None, json_data=True,\n",
522+
" return_json=True, return_headers=False, debug=None):\n",
523+
" req = urlrequest(url, verb, headers, route=route, query=query, data=data, json_data=json_data)\n",
524+
" if debug: debug(req)\n",
525+
" return urlread(req, return_json=return_json, return_headers=return_headers)\n",
526+
"\n",
527+
"test_fail(_org_urlsend, args=dict(url=url, verb=\"get\", headers=header, route=route), msg=\"'utf-8' codec can't decode\")"
528+
]
529+
},
496530
{
497531
"cell_type": "code",
498532
"execution_count": null,

0 commit comments

Comments
 (0)