Py学习  »  问与答

又是字符问题

1160974245 • 9 年前 • 5719 次点击  

上传文件到bcs上,问题是上传文件名是中文和纯数字就报错,字母加数字没问题。 想不通。


中文:ascii' codec can't encode characters in position 9-11: ordinal not in range(128) 数字:'utf8' codec can't decode byte 0x9c in position 140: invalid start byte 谢谢!


def upfile(request):
    global BUCKET,bcs
    if request.method == 'GET':
        return render_to_response('upload.html')
    elif request.method == 'POST':
        file = request.FILES['cs']
        f    = handfile(file)
        b = bcs.bucket(BUCKET)
        name = '/%s' % file.name
        o = b.object(name)
        o.put_file(f)
        os.remove(f)
        return HttpResponseRedirect('/p/')
def handfile(f):
    fpath = '/tmp/%s' % f.name
    with open(fpath,'wb+') as info:
        for chunk in f.chunks():
            info.write(chunk)
    return fpath
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/847
 
5719 次点击  
文章 [ 9 ]  |  最新文章 9 年前