authlib / authlib/authlib

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

Open
#537 3 comments 3 reactions 0 assignees View on GitHub
documentation
Dominant language
Python
Stars
5.4k
Forks
563
PR merge metrics
No merged PRs in 30d

Description

Same issue as [this SO user](https://stackoverflow.com/questions/75883174/typeerror-cannot-convert-url-object-to-bytes-following-authlib-google-auth-ex). I'm following the [official tutorial](https://docs.authlib.org/en/latest/client/fastapi.html) / blog post, but I get the following error when it gets to `oauth.google.authorize_redirect()`:

Code from tutorial:
```
@app.get("/login/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`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.