Reputation: 45
I am using an automation framework and I am getting random error after many iterations which is as follows. Can someone help me understand what this could correspond to !!
_os.environ['PATH'] = r'C:\DAL;' + _os.environ['PATH']
File "c:\Python26\lib\os.py", line 420, in __setitem__
putenv(key, item)
OSError: [Errno 22] Invalid argument
Function Call where it fails:
function:
plugin_xml_file_name = plugin_name
else:
plugin_xml_file_name = plugin_path + "\\" + plugin_name
#
_os.environ['PATH'] = r'C:\Intel\DAL;' + _os.environ['PATH']
_os.environ['PATH'] = r'C:\intel\dal;' + _os.environ['PATH']
_os.environ['PATH'] = _lakemore_path + ';' + _os.environ['PATH']
_os.environ['PATH'] = plugin_path + ';' + _os.environ['PATH']
Upvotes: 4
Views: 44282
Reputation: 91
Avoid including special characters like \a, \b, \t, \n, \r in your directory path. Instead use double slash whenever neccessary. Like \a, \b, \t, \n, \r.
For example FILEPATH: E:\android\new_dir\raw_data\books\Harry.csv
should be written as
E:\\android\\new_dir\\raw_data\\books\Harry.csv
Upvotes: 0
Reputation: 4093
Add one more "/"
in the last "/"
of path for example:
open('C:\Python34\book.csv')
to open('C:\Python34\\\book.csv')
Upvotes: 1
Reputation: 1121744
You are creating too long a path and the OS no longer accepts a longer environment variable.
Extend the path only once. Test for the presence of the paths you are adding:
path = _os.environ['PATH'].split(_os.pathsep)
for extra in (r'C:\Intel\DAL', r'C:\intel\dal', _lakemore_path, plugin_path):
if extra not in path:
_os.environ['PATH'] = _os.pathsep.join(extra, _os.environ['PATH'])
This code only adds new elements if not already present.
Upvotes: 4