{"action":"created","issue":{"url":"https://api.github.com/repos/houtianze/bypy/issues/195","repository_url":"https://api.github.com/repos/houtianze/bypy","labels_url":"https://api.github.com/repos/houtianze/bypy/issues/195/labels{/name}","comments_url":"https://api.github.com/repos/houtianze/bypy/issues/195/comments","events_url":"https://api.github.com/repos/houtianze/bypy/issues/195/events","html_url":"https://github.com/houtianze/bypy/issues/195","id":116935706,"number":195,"title":"os.walk的编码问题","user":{"login":"Jayatubi","id":4991045,"avatar_url":"https://avatars.githubusercontent.com/u/4991045?v=3","gravatar_id":"","url":"https://api.github.com/users/Jayatubi","html_url":"https://github.com/Jayatubi","followers_url":"https://api.github.com/users/Jayatubi/followers","following_url":"https://api.github.com/users/Jayatubi/following{/other_user}","gists_url":"https://api.github.com/users/Jayatubi/gists{/gist_id}","starred_url":"https://api.github.com/users/Jayatubi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jayatubi/subscriptions","organizations_url":"https://api.github.com/users/Jayatubi/orgs","repos_url":"https://api.github.com/users/Jayatubi/repos","events_url":"https://api.github.com/users/Jayatubi/events{/privacy}","received_events_url":"https://api.github.com/users/Jayatubi/received_events","type":"User","site_admin":false},"labels":[{"id":72715886,"url":"https://api.github.com/repos/houtianze/bypy/labels/enhancement","name":"enhancement","color":"84b6eb","default":true},{"id":303788964,"url":"https://api.github.com/repos/houtianze/bypy/labels/hard","name":"hard","color":"000000","default":false},{"id":72715889,"url":"https://api.github.com/repos/houtianze/bypy/labels/wontfix","name":"wontfix","color":"ffffff","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2015-11-14T16:20:45Z","updated_at":"2017-01-08T08:13:03Z","closed_at":"2017-01-08T08:13:03Z","body":"在最新的1.2.1版本里面，因为需要同步的目录里面有中文目录（尚且无法知道关于这些文件名具体是utf-8还是gbk的编码）。会导致os.walk出现类似：\n`UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 1`\n的错误。\n如果我直接在该目录执行`python -c \"import os; os.walk('.')\"` 则不会产生这个编码错误。\n之后发现在`bypy.py`对`os.walk`传递的参数均为`unicode`类型，这个便是导致上面的错误的原因。\n目前我没有找到更好的办法，只是在本地将所有进入`os.walk`之前的参数都做了类型转换例如在`__upload_dir`里面\n\n``` python\ndef __upload_dir(self, localpath, remotepath, ondup = 'overwrite'):\n    self.pd(\"Uploading directory '{}' to '{}'\".format(localpath, remotepath))\n    # it's so minor that we don't care about the return value\n    self.__mkdir(remotepath, dumpex = False)\n    localpath = str(localpath) # Convert `localpath` to `str`\n    for walk in os.walk(localpath, followlinks=self.__followlink):\n        self.__walk_upload(localpath, remotepath, ondup, walk)\n```\n\n因为目前只是用了`upload`的功能，尚未测试其他功能是否有类似的问题。\n"},"comment":{"url":"https://api.github.com/repos/houtianze/bypy/issues/comments/271137265","html_url":"https://github.com/houtianze/bypy/issues/195#issuecomment-271137265","issue_url":"https://api.github.com/repos/houtianze/bypy/issues/195","id":271137265,"user":{"login":"houtianze","id":99046,"avatar_url":"https://avatars.githubusercontent.com/u/99046?v=3","gravatar_id":"","url":"https://api.github.com/users/houtianze","html_url":"https://github.com/houtianze","followers_url":"https://api.github.com/users/houtianze/followers","following_url":"https://api.github.com/users/houtianze/following{/other_user}","gists_url":"https://api.github.com/users/houtianze/gists{/gist_id}","starred_url":"https://api.github.com/users/houtianze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houtianze/subscriptions","organizations_url":"https://api.github.com/users/houtianze/orgs","repos_url":"https://api.github.com/users/houtianze/repos","events_url":"https://api.github.com/users/houtianze/events{/privacy}","received_events_url":"https://api.github.com/users/houtianze/received_events","type":"User","site_admin":false},"created_at":"2017-01-08T08:13:03Z","updated_at":"2017-01-08T08:13:03Z","body":"后来总结了一下[Python & Filesystem Unicode](https://houtianze.github.io/python/unicode/2015/12/07/python-unicode.html)，感觉没有一个完美解决方案（如果文件名是一串没法解码成string的字节）。"}}
{"actor":{"display_login":"houtianze"}}