我在本地目录中的 test.py 旁边有一个名为 hello.txt 的文件,其中包含以下 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)
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我得到了这个:
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
Run Code Online (Sandbox Code Playgroud)
谷歌搜索这会导致几个点击,所有这些都指向相同的修复,以防路径将来移动,包括“导入类型之后”:
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
Run Code Online (Sandbox Code Playgroud)
我没有使用导入类型,但是否包含它在 PyDev 中似乎没有什么不同 - 无论哪种方式我都会收到错误。导致错误的行是:
unicode = unicode
Run Code Online (Sandbox Code Playgroud)
说,'未定义的变量'。
好吧,我的 Python 知识在这一点上摇摇欲坠,我在这个网站上寻找了类似的帖子,但没有找到一个足够具体的 basestring,我理解可以提供帮助。我知道我需要指定 basestring,但我不知道如何指定。有没有人足够慈善来为我指明正确的方向?
您可以更改 easywebdav 的 client.py 文件,例如此签入中的前两个更改:https://github.com/hhaderer/easywebdav/commit/983ced508751788434c97b43586a68101eaee67b
更改包括在 client.py 中替换basestring为str。
| 归档时间: |
|
| 查看次数: |
9291 次 |
| 最近记录: |