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

there is a bug when filename contains a non-ascii character #2407

Closed
mushanshitiancai opened this issue Jan 13, 2015 · 2 comments
Closed

there is a bug when filename contains a non-ascii character #2407

mushanshitiancai opened this issue Jan 13, 2015 · 2 comments

Comments

@mushanshitiancai
Copy link

I ues python 2.7.9 and requests 2.5.1
when I do like this:

files = {'file1':('中文','hello')}
r = requests.post('http://test',files=files)

the request is like this(copy from fiddler):

Content-Disposition: form-data; name="file1"; filename*=utf-8''%E4%B8%AD%E6%96%87

I think the format of filename is wrong.

the right format should be:

Content-Disposition: form-data; name="file1"; filename="中文"
@mushanshitiancai
Copy link
Author

in requests\packages\urllib3\fields.py

def format_header_param(name, value):
    if not any(ch in value for ch in '"\\\r\n'):
        result = '%s="%s"' % (name, value)
        try:
            result.encode('ascii')
        except UnicodeEncodeError:
            pass
        else:
            return result
    if not six.PY3:  # Python 2:
        value = value.encode('utf-8')
    value = email.utils.encode_rfc2231(value, 'utf-8')
    value = '%s*=%s' % (name, value)
    return value

I think this is related code.

When the Content-Type is multipart/form-data,is it correct ues this function to format heaer?

@sigmavirus24
Copy link
Contributor

Duplicate of #2313. Please search for existing issues before opening new ones in the future.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 8, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants