0

I'm trying to create a Flask app that talks to Google's API. However, I keep getting this error:

Traceback (most recent call last):
  File "hello.py", line 16, in <module>
    @app.route('google_api')
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1013, in decorator
    self.add_url_rule(rule, endpoint, f, **options)
  File "/Library/Python/2.7/site-packages/flask/app.py", line 62, in wrapper_func
    return f(self, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/flask/app.py", line 976, in add_url_rule
    rule = self.url_rule_class(rule, methods=methods, **options)
  File "/Library/Python/2.7/site-packages/werkzeug/routing.py", line 599, in __init__
    raise ValueError('urls must start with a leading slash')
ValueError: urls must start with a leading slash

I went through the Flask tutorial and the "Using OAuth 2.0 for Web Services" on Google's website. I'm not quite sure what I'm doing wrong, and I'm not quite sure what the error is telling me. It looks like it has something to do with with Flask? Here is my code:

from flask import Flask
from oauth2client import client

app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello world!"

@app.route('google_api')
def google_api():
    flow = client.flow_from_clientsecrets(
        'client_secrets.json',
        scope='https://www.googleapis.com/auth/prediction',
        redirect_uri='http://127.0.0.1:5000/redirect')

@app.route('/redirect')
def redir():
    return "Authenticated"


if __name__ == '__main__':
    app.debug = True
    app.run(threaded=True)

What am I doing wrong? How can I fix it?

2 Answers 2

3

I think you are missing the leading slash from your google api route.

@app.route('google_api')

Have you tried updating to

@app.route('/google_api')

Hope that helps

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

1 Comment

I would also suggest redirect_uri=flask.redirect(flask.url_for('redir')) so you can have your endpoints work on every domain.
0

Here are the import parts of the error you are getting.

 File "hello.py", line 16, in <module>
    @app.route('google_api')
...
ValueError: urls must start with a leading slash

Try:

    @app.route('/google_api')

Notice the forward slash before google_api

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.