python-3.4 – 如何克服Python 3.4 NameError:未定义名称“basestring”

我在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)

当我运行这个我得到这个:

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到相同的修复,如果将来移动路径,将包括“在导入类型后”:

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知识在这一点上停滞不前,我在这个网站上寻找类似的帖子,但没有找到一个特定的基本字符串,我理解帮助.我知道我需要指定basetring但我不知道如何.有人会慈善足以指出我正确的方向吗?

最佳答案 您可以更改easywebdav的client.py文件,例如此签入中的前两个更改:
https://github.com/hhaderer/easywebdav/commit/983ced508751788434c97b43586a68101eaee67b

更改包括在client.py中用str替换basetring.

点赞