# Issue with python file downloading from yum repository

**URL:** <https://community.sonatype.com/t/issue-with-python-file-downloading-from-yum-repository/5163>\
**Category:** Sonatype Nexus Repository\
**Tags:** nexus-repository, nexus-iq\
**Created:** [October 20, 2020, 2:12pm UTC](https://community.sonatype.com/t/issue-with-python-file-downloading-from-yum-repository/5163 "2020-10-20T14:12:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![miraclesky321](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@miraclesky321](https://community.sonatype.com/u/miraclesky321)\
**Post date:** [October 20, 2020, 2:12pm UTC](https://community.sonatype.com/t/issue-with-python-file-downloading-from-yum-repository/5163/1 "2020-10-20T14:12:15Z")

</div>

> #!/usr/bin/env python3  
> import json  
> import urllib.request
> 
> def main():
> 
> baseurl = ‘[http://127.0.0.1:8081/](http://127.0.0.1:8081/)’  
> downloadRepository = ‘yum-internet’  
> url = baseurl + ‘#browse/search/yum=repository\_name%3D’ + downloadRepository
> 
> ```
> response = urllib.request.urlopen(url)
> data = json.load(response)
> for item in data["items"]:
> for asset in item["assets"]:
> fileurl = asset["downloadUrl"]
> filename = downloadPath + fileurl.split('/')[-1] # '\' for Windows
> outfile = open(filename, "w")
> outfile.write(str(urllib.request.urlopen(fileurl).read()))
> outfile.close()
> if data["continuationToken"] is None:
> break
> else:
> # construct pagination url and loop
> url = baseurl + 'components?continuationToken=' + data["continuationToken"] + '&repository=' + downloadRepository
> 
> ```
> 
> if\_\_name\_\_==“ **main** ”:  
> main()

I am trying to use this python file code to download the dependencies at the right URL of my nexus repo, but the main problem is that the following code is giving me errors for the line data = json.load(response) which resulted in the following output,

> json.DecodeError Expecting value

. Tried using try except method but the line after that for item in data[items] resulted in the following output,

> NameError: data is not defined

is the URL correct? I am a bit worried that I am doing it wrongly, thus all the error occurs.  
any advice and help are appreciated, been working on this for ages. Thank you

---

<div class="post-metadata">

**Author:** ![dsawa](https://yyz1.discourse-cdn.com/flex047/user_avatar/community.sonatype.com/dsawa/32/729_2.png) [@dsawa](https://community.sonatype.com/u/dsawa)\
**Post date:** [October 20, 2020, 2:19pm UTC](https://community.sonatype.com/t/issue-with-python-file-downloading-from-yum-repository/5163/2 "2020-10-20T14:19:46Z")

</div>

This sounds more like you’re looking for general help with your Python script that I suggest you seek at forums like [Stack Overflow](https://stackoverflow.com/questions/tagged/python). However, it looks like you are trying to script against the Web UI which is generally not a good idea. For cases like this we have an API defined that you should consider using: [REST and Integration API](https://help.sonatype.com/repomanager3/rest-and-integration-api)
