我在本地目录中有一个名为 hello.txt 的文件以及 test.py,其中包含以下 Python 3.4 代码:
import easywebdav
webdav = easywebdav.connect('192.168.1.6', username='myUser', password='myPasswd', protocol='http', port=80)
srcDir = "myDir"
webdav.mkdir(srcDir)
webdav.upload("hello.txt", srcDir)
当我运行这个时,我得到这个:
Traceback (most recent call last):
File "./test.py", line 196, in <module>
webdav.upload("hello.txt", srcDir)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/easywebdav/client.py", line 153, in upload
if isinstance(local_path_or_fileobj, basestring):
NameError: name 'basestring' is not defined
谷歌搜索这个结果有几个点击,所有这些point https://github.com/oxplot/fysom/issues/1进行相同的修复,以防将来路径移动,包括“在导入类型之后”:
try:
unicode = unicode
except NameError:
# 'unicode' is undefined, must be Python 3
str = str
unicode = str
bytes = bytes
basestring = (str,bytes)
else:
# 'unicode' exists, must be Python 2
str = str
unicode = unicode
bytes = str
basestring = basestring
我没有使用导入类型,但包含或不包含它似乎在 PyDev 中没有什么区别 - 无论哪种方式我都会收到错误。导致错误的行是:
unicode = unicode
说“未定义的变量”。
好吧,我的 python 知识在这一点上动摇了,我在这个网站上寻找过类似的帖子,但没有找到一个足够具体的基础字符串,我理解可以提供帮助。我知道我需要指定基本字符串,但我不知道如何做。有人会足够仁慈地为我指明正确的方向吗?