Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

r.json() #815

Closed
ZYecho opened this issue Mar 6, 2016 · 5 comments
Closed

r.json() #815

ZYecho opened this issue Mar 6, 2016 · 5 comments

Comments

@ZYecho
Copy link

ZYecho commented Mar 6, 2016

I use python 3.5
async with session.get('http://www.zhihu.com') as r: json = await r.json()
the json = await r.json() always report Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8 is there any bugs ?

@kxepal kxepal added the wontfix label Mar 6, 2016
@kxepal
Copy link
Member

kxepal commented Mar 6, 2016

@ZYecho text/html is definitely not right content type for JSON data. Much likely you received not JSON data, but some HTML page instead. If your server returns JSON with such content type, you should fix it in first place to return correct application/json instead.

@kxepal kxepal closed this as completed Mar 6, 2016
@ZYecho
Copy link
Author

ZYecho commented Mar 6, 2016

r is an object of ClientResponse. I don't understand your expanlation.
Here is my problem!

I want to get the cookies after I login (www.zhihu.com) by posting the data.

but according to documents,

Response cookies contain only values, that were in Set-Cookie headers of the last request in redirection chain. To gather cookies between all redirection requests you can use aiohttp.ClientSession object.

how can I get the correct cookies after I login?

@kxepal
Copy link
Member

kxepal commented Mar 6, 2016

@ZYecho
Use the same session for login request and all the following ones.

@popravich
Copy link
Member

Hi, @ZYecho, I think I've got your problem:
async with session.get('http://www.zhihu.com') as r: json = await r.json()
this decodes page body as json.
If you need to access cookies after request you should do something like this:

await session.get('http://www.zhihu.com')
print(session.cookies)

Also see updated docs in #817

@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants