Issue with python file downloading from yum repository

#!/usr/bin/env python3
import json
import urllib.request

def main():

baseurl = ‘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

This sounds more like you’re looking for general help with your Python script that I suggest you seek at forums like Stack Overflow. 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

1 Like