[FIX] website_sale_digital: special character in filename
- Create a product with attachment, and name the attachment 'テスト'
- Purchase the product, make a payment, validate and pay the invoice
- Go to My Orders under My Account, open the order, and try to download
the file 'テスト'.
An error 500 is raised due to a UnicodeEncodeError.
```
File "/home/nim/src/odoo/addons/website_sale_digital/controllers/main.py", line 104, in download_attachment
return http.send_file(data, filename=attachment['name'], as_attachment=True)
File "/home/nim/src/odoo/odoo/http.py", line 1595, in send_file
headers.add('Content-Disposition', 'attachment', filename=filename)
File "/usr/lib/python2.7/dist-packages/werkzeug/datastructures.py", line 1093, in add
_value = _options_header_vkw(_value, kw)
File "/usr/lib/python2.7/dist-packages/werkzeug/datastructures.py", line 830, in _options_header_vkw
for k, v in kw.items()))
File "/usr/lib/python2.7/dist-packages/werkzeug/http.py", line 212, in dump_options_header
segments.append('%s=%s' % (key, quote_header_value(value)))
File "/usr/lib/python2.7/dist-packages/werkzeug/http.py", line 165, in quote_header_value
value = str(value)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
```
opw-766568
This commit is contained in:
@@ -101,6 +101,6 @@ class WebsiteSaleDigital(website_account):
|
||||
return request.not_found()
|
||||
elif attachment["datas"]:
|
||||
data = StringIO(base64.standard_b64decode(attachment["datas"]))
|
||||
return http.send_file(data, filename=attachment['name'], as_attachment=True)
|
||||
return http.send_file(data, filename=attachment['name'].encode('utf-8'), as_attachment=True)
|
||||
else:
|
||||
return request.not_found()
|
||||
|
||||
Reference in New Issue
Block a user