Open k8n opened 10 years ago
And here is a "monkey patch" for requests' field encoder. Say, mod_requests.py ...
#!/usr/bin/env python
# coding: utf-8
__author__ = 'k8n'
import requests
import email.utils
from requests.packages.urllib3.packages import six
def mod_format_header_param(name, value):
"""
Helper function to format and quote a single header parameter.
See original doc, minus rfc2331 for non-multiline strings.
"""
if not any(ch in value for ch in '"\\\r\n'):
result = '%s="%s"' % (name, value)
try:
result.encode('ascii')
except UnicodeEncodeError:
pass
finally:
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
#monkey patching
requests.packages.urllib3.fields.format_header_param = mod_format_header_param
Hey there,
I've sent an email to Box's api support. Let's see what they say :)
Here is a trace (upload_file executed via box.py) that fails with "status":400,"code":"invalid_request_parameters":
Here is a trace from an equivalent openration via curl:
Seems Box Content API is not liking RFC 2231-encoded file names. More related discussion on this. And a hack-around?
I'm not sure yet what to tell requests library to send filename unencoded.