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

invalid character in header url #5730

Closed
saarsa opened this issue May 22, 2021 · 4 comments
Closed

invalid character in header url #5730

saarsa opened this issue May 22, 2021 · 4 comments
Labels

Comments

@saarsa
Copy link

saarsa commented May 22, 2021

my python env
Python 3.8.5
aiohttp 3.7.4.post0
multidict 5.1.0
yarl 1.6.3
Hi sorry for the question but I have an error that I can not understand
I'm trying to run this code
`async def main():
async with aiohttp.ClientSession() as session:
async with session.get("https://tase.co.il") as resp:
print(resp.status)
print(await resp.text())

loop = asyncio.get_event_loop()
loop.run_until_complete(main())`

But it brings me back
raise ClientResponseError(aiohttp.client_exceptions.ClientResponseError: 400, message='invalid character in header', url=URL('https://www.tase.co.il/')
Why is this happening to me?

@g66-gopanear
Copy link

I am getting the same issue.
This is my header : {'X-Avangate-Authentication': 'code="255435546325215709" date="2021-06-11 09:14:04" hash="f312b75343er41f44dce26a3d4fdb6dc3e5a0"'}

@Hanaasagi
Copy link
Member

@saarsa
It's the server' problem. It has a invisible char \x01 in the response header.

Run this command in you shell.

curl https://tase.co.il/ --http1.1 -L -ivs --user-agent "Python/3.9 aiohttp/3.7.4" -H "Accept-Encoding: gzip, deflate" -vvv > output

And use the vim to open this file output

图片

The highlight place is the invalid char. Use some hex editor tools to check this position, it's \x01.


The http-parser's validation rules:
https://github.com/nodejs/http-parser/blob/2343fd6b5214b2ded2cdcf76de2bf60903bb90cd/http_parser.c#L445-L451

/**
 * Verify that a char is a valid visible (printable) US-ASCII
 * character or %x80-FF
 **/
#define IS_HEADER_CHAR(ch)                                                     \
  (ch == CR || ch == LF || ch == 9 || ((unsigned char)ch > 31 && ch != 127))


@Hanaasagi
Copy link
Member

@g66-gopanear Please check the server's response header.

@Hanaasagi
Copy link
Member

Please reopen if your have other questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants