又拍云python sdk的一个bug

upyun的pysdk存在bug,会导致部分文件上传失败。测试图片

问题原因

部分图像处理软件会去掉图片的description,而python的fileno如果没有取到description会抛出一个异常,程序没有处理这个异常,从而导致了无法上传。 pysdk有判断这个方法是否存在,但是没有处理这个异常。 https://docs.python.org/3/library/io.html#io.IOBase.fileno

解决办法

打开sdk的upyun.py中的173行处,修改

    if hasattr(value, 'fileno'):
        length = os.fstat(value.fileno()).st_size
    elif hasattr(value, '__len__'):
        length = len(value)
        headers['Content-Length'] = length
    elif value is not None:
        raise UpYunClientException('object type error')

    if hasattr(value, 'getvalue'):
        length = len(value.getvalue())
        headers['Content-Length'] = length
    elif hasattr(value, '__len__'):
        length = len(value)
        headers['Content-Length'] = length
    elif hasattr(value, 'fileno'):
        length = os.fstat(value.fileno()).st_size
        headers['Content-Length'] = length
    elif value is not None:
        raise UpYunClientException('object type error')

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

*

code