Skip to content

aiohttp.ClientSession incorrectly decoding special characters (parentheses) before making request #7341

@piotr-gregrowski

Description

@piotr-gregrowski

Describe the bug

The url that I pass into the .get() function is not being handled correctly when there are parentheses in the path. This is causing issues when trying to download documents that use the standard naming convention for copies:
my_document (1).pdf

The expected url for that document download would look something like:
https://python.org/my_document%20%281%29.pdf
with the following encodings:

  • space -> %20
  • left parenthesis ( -> %28
  • right parenthesis ) -> %29

Instead it is being decoded at some point and ends up looking like this:
https://www.python.org/document%20(1).pdf

To Reproduce

async with aiohttp.ClientSession() as session:
        async with session.get('http://python.org/my_document%20%281%29') as response:
                print(response.request_info)

> RequestInfo(url=URL('https://www.python.org/my_document%20(1).pdf'), method='GET', headers=<CIMultiDictProxy('Host': 'www.python.org', ...)>, real_url=URL('https://www.python.org/document%20(1).pdf'))

Expected behavior

async with aiohttp.ClientSession() as session:
        async with session.get('http://python.org/my_document%20%281%29') as response:
                print(response.request_info)

> RequestInfo(url=URL('https://www.python.org/my_document%20%281%29.pdf'), method='GET', headers=<CIMultiDictProxy('Host': 'www.python.org', ...)>, real_url=URL('https://www.python.org/document%20%281%29.pdf'))

Logs/tracebacks

See above

Python Version

$ python --version

Python 3.11.1

aiohttp Version

$ python -m pip show aiohttp

Name: aiohttp
Version: 3.8.4
Summary: Async http client/server framework (asyncio)
Home-page: https://github.com/aio-libs/aiohttp
Author: 
Author-email: 
License: Apache 2
Location: [redacted}
Requires: aiosignal, async-timeout, attrs, charset-normalizer, frozenlist, multidict, yarl
Required-by: aiobotocore, aioresponses

multidict Version

$ python -m pip show multidict

Name: multidict
Version: 6.0.2
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: [redacted]
Requires: 
Required-by: aiohttp, yarl

yarl Version

$ python -m pip show yarl

Name: yarl
Version: 1.8.1
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl/
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: [redacted]
Requires: idna, multidict
Required-by: aio-pika, aiohttp, aiormq

OS

macOS

Related component

Client

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions