我以为我能用思考和谷歌来解决这个问题,但我不是......
我asana API python wrapper有一个forked and extended,所以它处理文件上传。
我在我的管理Web应用程序中使用它来创建任务并将.pdf文件附加到它们。
请求和响应仅支持UTF-8字符编码。
只要我在我附加的文件名中没有德语变音符号(在本例中为ö),一切正常。
这就是我的工作:我从mysql数据库(utf-8中的所有内容)中获取文件URL,并将其作为attach_to_task()
函数的参数。
这是一个例子:
u'/Users/Foo/directory/inv\xf6ice.pdf'
asana API python包装器的POST方法然后抛出'Received non 2xx or 404 status code on call'
并且不上传文件。
但是,如果我手动将文件名中包含'ö'的文件上传到asana,然后使用python API包装器获取有关任务附件的信息,我会
{u'id': 99347997, u'name': u'inv\xf6ice.pdf'}
回来。
UTF-8中的'p''是'\ xc3 \ xb6'。
但我真的不明白我试图上传的\xf6
与他们回馈的\xf6
之间有什么区别。但是,问题必须存在于包含变音符号的文件名中,因为对于无变音文件,它可以正常工作。
有人可以暗示我做错了吗?谢谢。
==========
修改
以下是完整的错误消息:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/webapp2-2.5.1-py2.7.egg/webapp2.py", line 1536, in __call__
rv = self.handle_exception(request, response, e)
File "/Library/Python/2.7/site-packages/webapp2-2.5.1-py2.7.egg/webapp2.py", line 1530, in __call__
rv = self.router.dispatch(request, response)
File "/Library/Python/2.7/site-packages/webapp2-2.5.1-py2.7.egg/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/Library/Python/2.7/site-packages/webapp2-2.5.1-py2.7.egg/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/Library/Python/2.7/site-packages/webapp2-2.5.1-py2.7.egg/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/Library/Python/2.7/site-packages/webapp2-2.5.1-py2.7.egg/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "main.py", line 877, in post
self.asana_handler.attach_file_to_task(int(new_task_id), rechn[:-3] + 'pdf')
File "/Users/Peter/Projekte/app/utils/asana.py", line 401, in attach_file_to_task
return self._asana_post('tasks/%d/attachments' % task_id, payload, files=True)
File "/Users/Peter/Projekte/app/utils/asana.py", line 119, in _asana_post
if (self.handle_exception(r) > 0):
File "/Users/Peter/Projekte/app/utils/asana.py", line 60, in handle_exception
raise AsanaException('Received non 2xx or 404 status code on call')
AsanaException: Received non 2xx or 404 status code on call
===========================
编辑2
这是响应标题:
{'x-robots-tag': 'none', 'transfer-encoding': 'chunked', 'set-cookie':
'TooBusyRedirectCount=0', 'x-asana-content-string-length': '54', 'server': 'nginx',
'connection': 'keep-alive', 'pragma': 'no-cache', 'cache-control': 'no-store', 'date':
'Fri, 31 Jan 2014 19:47:28 GMT', 'x-asana-preferred-release-revision':
'20140131_010208_eb5bb829738a01056cb5d46b626ed2169387b5ed', 'content-type':
'application/json; charset=UTF-8'}
在详细(调试)模式下,我也得到了这个:
{u'errors': [{u'message': u'file: File is not an object'}]}
curl -v没有问题,并说出以下内容:
* Adding handle: conn: 0x7f88da803a00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7f88da803a00) send_pipe: 1, recv_pipe: 0
* About to connect() to app.asana.com port 443 (#0)
* Trying 107.20.161.243...
* Connected to app.asana.com (107.20.161.243) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
* Server certificate: *.asana.com
* Server certificate: Go Daddy Secure Certification Authority
* Server certificate: Go Daddy Class 2 Certification Authority
* Server auth using Basic with user 'f83V8fK8LZfoVRoA2CSIF'
> POST /api/1.0/tasks/986184874/attachments HTTP/1.1
> Authorization: Basic ZjgzVjhmSy42S0pXOExaZm9WUm9BMkNTSUY6
> User-Agent: curl/7.30.0
> Host: app.asana.com
> Accept: */*
> Content-Length: 28625
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------212d9ef46409
>
< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
* Server nginx is not blacklisted
< Server: nginx
< Date: Fri, 31 Jan 2014 20:08:38 GMT
< Content-Type: application/json; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< X-Asana-Content-String-Length: 66
< Pragma: no-cache
< Set-Cookie: TooBusyRedirectCount=0
< Cache-Control: no-store
< X-Server-Name: prod-ws020.ec2
< X-Asana-Preferred-Release-Revision: 20140131_010208_eb5bb829738a01056cb5d46b626ed2169387b5ed
< X-Robots-Tag: none
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< Datacenter-Time-End: 1391198918.072
<
* Connection #0 to host app.asana.com left intact
{"data":{"id":995785926,"name":"invöic.pdf"}}