Archive
ignore a specific OSError error
Problem
I have a Google Nexus tablet and its file system is available via the MTP protocol. I can access the tablet’s file system in command-line but when I want to copy a file to it with a Python script, I get this error:
... File "something.py", line 81, in create_in_dest shutil.copy(src_long, dest_long) File "/usr/lib/python3.5/shutil.py", line 236, in copy copymode(src, dst, follow_symlinks=follow_symlinks) File "/usr/lib/python3.5/shutil.py", line 138, in copymode chmod_func(dst, stat.S_IMODE(st.st_mode)) OSError: [Errno 95] Operation not supported ...
It means that the permissions of the original file cannot be set on the destination file. The file is copied but then this error is raised. If the permissions are not the same, who cares? Not a big deal. So how to ignore this specific error (Errno 95)?
Solution
import errno import shutil def my_copy(src, dest): try: shutil.copy(src, dest) except OSError as e: if e.errno == 95: pass
This error code 95 could also be written as errno.ENOTSUP
(it’s a constant in the errno
module).
Anaconda: problem with the readline module under Manjaro
Problem
I tried the Anaconda Python distribution under Manjaro, but there was a problem with the “readline” module:
>>> import readline Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: libncursesw.so.5: cannot open shared object file: No such file or directory
Solution
As root:
# cd /usr/lib # ln -s libncursesw.so libncursesw.so.5
It may be an ugly hack, but it solved the issue for me.
Blog Stats
- 1,422,023 hits
Random Post
Recent Posts
Archives
- February 2019 (1)
- January 2019 (1)
- August 2018 (1)
- July 2018 (4)
- June 2018 (5)
- May 2018 (1)
- March 2018 (2)
- February 2018 (1)
- January 2018 (2)
- December 2017 (2)
- October 2017 (1)
- August 2017 (1)
- May 2017 (2)
- April 2017 (1)
- March 2017 (1)
- February 2017 (3)
- January 2017 (5)
- December 2016 (3)
- October 2016 (2)
- September 2016 (1)
- August 2016 (4)
- July 2016 (3)
- June 2016 (2)
- May 2016 (2)
- April 2016 (1)
- March 2016 (4)
- February 2016 (1)
- January 2016 (4)
- December 2015 (5)
- November 2015 (8)
- October 2015 (2)
- September 2015 (3)
- August 2015 (6)
- July 2015 (4)
- June 2015 (1)
- May 2015 (3)
- April 2015 (2)
- February 2015 (1)
- January 2015 (6)
- December 2014 (5)
- November 2014 (2)
- October 2014 (1)
- September 2014 (1)
- August 2014 (14)
- July 2014 (3)
- June 2014 (6)
- May 2014 (3)
- April 2014 (2)
- March 2014 (4)
- February 2014 (3)
- January 2014 (19)
- December 2013 (8)
- November 2013 (9)
- October 2013 (4)
- September 2013 (10)
- August 2013 (16)
- July 2013 (4)
- June 2013 (7)
- May 2013 (7)
- April 2013 (3)
- March 2013 (12)
- February 2013 (2)
- January 2013 (10)
- December 2012 (18)
- November 2012 (3)
- October 2012 (4)
- September 2012 (5)
- August 2012 (1)
- July 2012 (1)
- May 2012 (8)
- April 2012 (9)
- March 2012 (17)
- February 2012 (3)
- January 2012 (8)
- November 2011 (11)
- October 2011 (7)
- September 2011 (17)
- August 2011 (5)
- June 2011 (1)
- May 2011 (7)
- April 2011 (21)
- March 2011 (21)
- February 2011 (7)
- December 2010 (4)
- November 2010 (1)
- October 2010 (16)
- September 2010 (15)