python oserror 22_Python错误:OSError:[Errno 22]参数无效

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']

解决方案

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值