How to overcome Python 3.4 NameError: name "basestring" not defined

I have a hello.txt file in a local directory next to test.py that contains this Python 3.4 code:

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)

When I run this, I get the following:

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

As a result of a Google search, this leads to several hits, all of which point refer to the same fix, which, if the paths are transferred in the future, includes “right after the import types”:

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

I did not use import types, but whether or not to include it does not seem to matter in PyDev - I get an error anyway. The line causing the error is as follows:

unicode = unicode

saying 'undefined variable'.

, python , basestring, , . , basestring, , . - , ?

+4
1
+2

All Articles