Search code examples
pythonpytestcodacy

Audit url open for permitted schemes. Allowing use of "file:" or custom schemes is often unexpected


I am using this statement in Python:

 jsonreq = json.dumps({'jsonrpc': '2.0', 'id': 'qwer', 'method': 'aria2.pauseAll'})
 jsonreq = jsonreq.encode('ascii')
 c = urllib.request.urlopen('http://localhost:6800/jsonrpc', jsonreq)

I am getting this warning/error when I perform code quality test

Audit url open for permitted schemes. Allowing use of "file:" or custom schemes is often unexpected.


Solution

  • I think this is what you need

    import urllib.request
    
    req = urllib.request.Request('http://www.example.com')
    with urllib.request.urlopen(req) as response:
        the_page = response.read()