Forums

requests.exceptions.MissingSchema: Invalid URL No scheme supplied

Whenever I try to use url provided as a keyword argument, it's striped of the protocol and slashes, for example "https://twitter.com/" gets truncated to "twitter.com/".

Could you provide some sample code?

It is simple Flask app (which in the local environment works as expected):

@app.route('/<path:url>')
def proxy(url):
    try:
        r = requests.get(url)
        r.raise_for_status()
        return addTag(r.text)
    except requests.exceptions.HTTPError as e:
        return e.response.text

I think the path converter type accepts string with slashes but will sanitize double slashes into one (as in file paths). If you want to provide the protocol as well, you could try something like:

@app.route('/<protocol>/<path:url>')
def proxy(protocol, url):
    try:
        r = requests.get(f"{protocol}://{url}")
        r.raise_for_status()
        return addTag(r.text)
    except requests.exceptions.HTTPError as e:
        return e.response.text

Mind that free accounts have restricted internet access on PythonAnywhere so you may not be able to connect with the given url.