这里的Asana-API unicode(uft8)问题是什么(文件附件)?

2024-06-07 12:21:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我以为我可以用思维和谷歌来解决这个问题,但我没有。。。在

有一个asana API python wrapper,我forked and extended,所以它处理文件上传。在

我在我的管理web应用程序中使用它来创建任务并向它们附加.pdf文件。在

asana API docs指定

Only the UTF-8 character encoding is supported for both requests and responses.

只要我在附加的文件名中没有德语元音变音(在本例中是廑),一切都会正常工作。在

我要做的是:从mysql数据库(所有内容都是utf-8)中获取一个文件URL,并将其作为attach_to_task()函数的参数。在

这就是一个例子:

u'/Users/Foo/directory/inv\xf6ice.pdf'

asanaapi python包装器的POST方法随后抛出一个'Received non 2xx or 404 status code on call',并且不上载该文件。在

但是,如果我手动将文件名中包含“ö”的文件上载到asana,然后使用pythonapi包装器来获取关于任务附件的信息,那么

{u'id': 99347997, u'name': u'inv\xf6ice.pdf'}回来。在

someone else's post里写着

'ö' in UTF-8 is '\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

这是响应标头:

^{pr2}$

在详细(调试)模式下,我还得到:

{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"}}

Tags: 文件toinpyselfappserverline

热门问题