Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openwrt 上跑该脚本 unicode出错 #11

Closed
a19284 opened this issue Mar 11, 2014 · 10 comments
Closed

openwrt 上跑该脚本 unicode出错 #11

a19284 opened this issue Mar 11, 2014 · 10 comments

Comments

@a19284
Copy link

a19284 commented Mar 11, 2014

不知为何unicode还是有问题,能否帮忙检查下

OS:openwrt

ENV:
LANG='zh_CN.UTF-8'
LANGUAGE='zh_CN.UTF-8'
LC_ALL='zh_CN.UTF-8'
PYTHONIOENCODING='UTF-8'
TERM='linux'

root@CentiFLY:/mnt/sda3/Downloads# python bypy.py downfile test/测试3d.mp4 -d
Token file: '/root/.bypy.json'
Hash Cache file: '/root/.bypy.pickle'
App root path at Baidu Yun '/apps/bypy'
sys.stdin.encoding = UTF-8

sys.stdout.encoding = UTF-8

Token loaded:
Downloading '/apps/bypy/test/测试3d.mp4' as '测试3d.mp4'
Getting info of remote file '/apps/bypy/test/测试3d.mp4' for later verification
__get_file_info(): rdir : /apps/bypy/test | rfile: 测试3d.mp4
GET https://pcs.baidu.com/rest/2.0/pcs/file
actargs: (u'/apps/bypy/test/\u6d4b\u8bd53d.mp4', {})
Params: {u'path': u'/apps/bypy/test', u'order': u'asc', u'method': u'list', u'by': u'name'}
HTTP Status Code: 200
Request OK, processing action
Request all goes fine
Checking if we already have the copy locally
[21:58:29] Exception occurred:
Traceback (most recent call last):
File "bypy.py", line 2463, in main
result = getattr(by, args.command[0])(*uargs)
File "bypy.py", line 1662, in downfile
result = self.__downfile(pcsrpath, localfile)
File "bypy.py", line 1599, in __downfile
if os.path.isfile(localfile):
File "/usr/lib/python2.7/genericpath.py", line 29, in isfile
st = os.stat(path)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

@houtianze
Copy link
Owner

我看一下,谢谢反馈。

@a19284
Copy link
Author

a19284 commented Mar 12, 2014

用 if os.path.isfile(localfile.encode('utf-8')) 来代替原来的 if os.path.isfile(localfile) , 可以修正这个错误,不过相关变量太多,能否统一解决下? 估计是输入参数没有用utf-8强制encode导致的,仅供参考

@houtianze
Copy link
Owner

有点奇怪,按理应该都是Unicode,不知道为啥不行。如果你说的能行,那我猜你把这一行:

uargs.append(unicode(arg, SystemEncoding))

改成:

uargs.append(arg.encode('utf-8')))

能解决问题不?

@houtianze
Copy link
Owner

没有回应,先暂时关掉 ^.^

@muziling
Copy link

我试着把3558行的改成 uargs.append(arg.encode('utf-8')),也不行,在openwrt上

Traceback (most recent call last):
File "bypy.py", line 3560, in main
result = getattr(by, args.command[0])(*uargs)
File "bypy.py", line 2655, in downdir
return self.__walk_remote_dir(rpath, self.__proceed_downdir, (rpath, lpath))
File "bypy.py", line 2599, in __walk_remote_dir
return self.__walk_remote_dir_recur(remotepath, proceed, remotepath, args, skip_remote_only_dirs)
File "bypy.py", line 2578, in __walk_remote_dir_recur
subresult = proceed(remotepath, dirjs, filejs, args)
File "bypy.py", line 2637, in __proceed_downdir
self.__downfile(rfile, lfile)
File "bypy.py", line 2425, in __downfile
if not self.__shallinclude(localfile, remotefile, False):
File "bypy.py", line 1533, in __shallinclude
if os.path.exists(lpath) and (not os.access(lpath, os.R_OK)):
File "/tmp/p/usr/lib/python2.7/genericpath.py", line 18, in exists
UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-14: ordinal not in range(128)

Abort

@muziling
Copy link

我在 def __downfile(self, remotefile, localfile): 第一行加入 localfile = localfile.encode('utf-8'),可以正常下载了。

@houtianze
Copy link
Owner

感谢提供的这个修改。貌似这个可以解决Python 2.7下os.walk()天生Unicode不足的问题 😄 ,等我确认了加进去。

@septs
Copy link
Contributor

septs commented Mar 31, 2016

@houtianze
Copy link
Owner

@septs 感谢提供信息。

不过去AppleDNS那边看了一下,这个貌似还是OpenWRT的locale处理不太完美有关,其他的*nix没听说有这个问题。

@houtianze
Copy link
Owner

鉴于这个好像还是要在OpenWRT上改,这里就不处理直接关闭了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants