0

I'm working on some code that pulls course info from Canvas. As pure python, it works fine. If I try to incorporate it with Flask, I get the following error

requests.exceptions.MissingSchema: Invalid URL 'run/api/v1/courses/1234567': No schema supplied. Perhaps you meant http://run/api/v1/courses/1234567?

This is the code in question:

Canvas file

import sys
from canvasapi import Canvas

def getinfo():
    canvasurl = "https://canvas.instructure.com/";
    canvastoken = #Redacted for this example

try:
    canvastoken = sys.argv[1];
    canvasurl = sys.argv[2];
except:
   print()


#Create a new canvas object passing in the newly aquired url and token
canvas = Canvas(canvasurl, canvastoken);

#print(canv)

# Create a new course oject -- passing in course number as a parameter
# Course number is currently hard coded

print(canvas.get_course(1234567))

Flask file code (the file that I'm trying to run):

from flask import Flask
import canvas

canvas.getinfo()

app = Flask(__name__)


@app.route('/')
def hello_world():
    return 'Hello World!'


if __name__ == '__main__':
    app.run()
1
  • what is the URL that you are using to test this? Commented Mar 15, 2019 at 6:04

1 Answer 1

1

No schema provided usually means you haven't specified the http:// or https:// in the URL.

In the code you provided, I don't see any reference to a run/api/v1/courses/1234567. One possibility is if you are using the url_for method from requests anywhere in your code, try setting _external=True:

url = url_for('relativeURL', _external=True)

This allows Flask to construct an absolute URL (i.e., a URL with domain included).

If you aren't using url_for, check other places in your code where you might be omitting the http or https from the URL.

If you update your question to include the part that refers to the offending URL, we might be able to provide more specific help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.