2014-09-30 75 views
4

我有一個名爲hello.txt的沿側test.py本地目錄中的文件,其中包含此的Python 3.4代碼:如何克服的Python 3.4 NameError:名字「即basestring」沒有定義

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知識在這一點上動搖了,我在這個網站上尋找類似的帖子,沒有找到一個足夠的基礎字符串,我明白幫助。我知道我需要指定basestring,但我不知道如何去做。任何人都會有足夠的慈善來指引我走向正確的方向嗎?

+0

您使用的是什麼版本的easywebdav? – ooga 2014-09-30 21:57:24

+0

easywebdav 1.2.0 – volvox 2014-10-01 11:11:15

回答

2

您可以更改easywebdav的client.py文件就像這個簽入前兩個變化:https://github.com/hhaderer/easywebdav/commit/983ced508751788434c97b43586a68101eaee67b

的變化包括在client.py通過str更換basestring

+0

作爲對這種情況的任何人的簡短說明,在上述固定的情況下,請記住webdav.upload('local/path/to/file','remote/target/* file *')。即使相同,也不要忘記目標文件名。 – volvox 2014-10-01 11:57:37

+0

死鏈接。你能否提供另一個例子? – opyate 2015-03-13 12:44:21

+0

https://github.com/amnong/easywebdav/commit/983ced508751788434c97b43586a68101eaee67b – thebjorn 2015-03-14 21:36:39

相關問題