Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

TypeError: cannot convert 'URL' object to bytes with oauth.google.authorize_redirect() #537

Open
Jsalaz1989 opened this issue Apr 2, 2023 · 3 comments

Comments

@Jsalaz1989
Copy link

Same issue as this SO user. I'm following the official tutorial / blog post, but I get the following error when it gets to oauth.google.authorize_redirect():

Code from tutorial:

@app.get("/#/google")
async def login_via_google(request: Request):
    redirect_uri = request.url_for('auth_via_google')
    return await oauth.google.authorize_redirect(request, redirect_uri)    # breaks here

@app.get("/auth/google")
async def auth_via_google(request: Request):
    token = await oauth.google.authorize_access_token(request)
    user = token['userinfo']
    return dict(user)

The error:

File "/home/.venv/lib/python3.10/site-packages/authlib/common/encoding.py", line 15, in to_bytes
  return bytes(x)
TypeError: cannot convert 'URL' object to bytes

I'm on fastapi==0.95.0 and Authlib==1.2.0.

@nurettn
Copy link

nurettn commented Apr 2, 2023

#535

@Jsalaz1989
Copy link
Author

Thanks for linking to that, it helped me realize that, at least in my case, wrapping the oauth.google.authorize_redirect() with str does the trick:

@app.get("/#/google")
async def login_via_google(request: Request):
    redirect_uri = request.url_for('auth_via_google')
    return await oauth.google.authorize_redirect(request, str(redirect_uri)) # wrap with str()

@ezeparziale
Copy link

Thanks for linking to that, it helped me realize that, at least in my case, wrapping the oauth.google.authorize_redirect() with str does the trick:

@app.get("/#/google")
async def login_via_google(request: Request):
    redirect_uri = request.url_for('auth_via_google')
    return await oauth.google.authorize_redirect(request, str(redirect_uri)) # wrap with str()

adding str work fine

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants