开发者社区> 问答> 正文

python SDK的oss_sample.py运行错误

提示信息



==============================
put bucket  test2011-nov-0910-49-58 OK
==============================
bucket list size is:  3
bucket list is:
(u'test2011-nov-0910-41-07', u'2011-11-09T02:41:25.000Z')
(u'test2011-nov-0910-49-49', u'2011-11-09T02:50:07.000Z')
(u'test2011-nov-0910-49-58', u'2011-11-09T02:50:16.000Z')
==============================
Traceback (most recent call last):
  File "C:\Users\mshu\Downloads\阿里云\OSS_Python_API\oss\oss_sample.py", line 60, in <module>
    res = oss.put_object_from_string(bucket, object, input_content, content_type, headers)
  File "C:\Users\mshu\Downloads\阿里云\OSS_Python_API\oss\oss_api.py", line 337, in put_object_from_string
    res = self.put_object_from_fp(bucket, object, fp, content_type, headers)
  File "C:\Users\mshu\Downloads\阿里云\OSS_Python_API\oss\oss_api.py", line 447, in put_object_from_fp
    conn = self._open_conn_to_put_object(bucket, object, filesize, content_type, headers)
  File "C:\Users\mshu\Downloads\阿里云\OSS_Python_API\oss\oss_api.py", line 385, in _open_conn_to_put_object
    conn.putheader(k, headers[k])
  File "C:\Python27\lib\httplib.py", line 924, in putheader
    str = '%s: %s' % (header, '\r\n\t'.join(values))
TypeError: sequence item 0: expected string, int found


如何解决?

展开
收起
ego008 2011-11-09 11:07:38 11681 0
2 条回答
写回答
取消 提交回答
  • 用py2.7,把oss_api.py 里的 conn.putheader(k, headers[k]) 改成conn.putheader(str(k), str(headers[k])) 没问题了。

    谢谢
    2011-11-09 15:57:57
    赞同 展开评论 打赏
  • 回 楼主(ego008) 的帖子
    这是因为conn.putheader(k, headers[k])在你现在使用的python版本中一定需要是字符串,而headers[k]是整数,需要把k和headers[k]转换成str,临时解决方法是把conn.putheader(k, headers[k]) 改成conn.putheader(str(k), str(headers[k])),这个修复会在下一次发布中解决。
    2011-11-09 13:52:40
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
OSS运维进阶实战手册 立即下载
《OSS运维基础实战手册》 立即下载
OSS运维基础实战手册 立即下载