TypeError: environment can only contain strings
  • 发布时间: 2012/11/24 23:21
  • 阅读: 408
  • 收藏: 0
  • 点赞: 0
  • 评论: 0
工作机上安装了ActivePython 2.6,一直用来编写测试脚本。一次安装了WebDriver 2.13的代码后,运行了启动FireFox来进行Web自动化测试,却抛出了下面的异常,

Traceback (most recent call last):
  File "D:\workspace\boss_autotest\lib\basictestcase.py", line 77, in run
    self.preTest()
  File "D:\workspace\boss_autotest\tc\add_kfaccount.py", line 33, in preTest
    self.browser=browserinstance.setbrowser('firefox',self.url)
  File "D:\workspace\boss_autotest\tc\initbrowser.py", line 36, in setbrowser
    self.browser = webdriver.Firefox()
  File "C:\Python26\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 51, in __init__
    self.binary, timeout),
  File "C:\Python26\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 47, in __init__
    self.binary.launch_browser(self.profile)
  File "C:\Python26\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 43, in launch_browser
    self._start_from_profile_path(self.profile.path)
  File "C:\Python26\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 65, in _start_from_profile_path
    env=self._firefox_env).communicate()
  File "C:\Python26\lib\subprocess.py", line 633, in __init__
    errread, errwrite)
  File "C:\Python26\lib\subprocess.py", line 842, in _execute_child
    startupinfo)
TypeError: environment can only contain strings

这个TypeError,大概的意思就是当前environment环境变量environment,含有value值类型非string的key。于是在subprocess.py,加入下面的代码,

import types
for k, v in env.iteritems():

    if type(v) is not types.StringType:  print k, v, type(v)

结果打出来时这样的,
TK_LIBRARY --- C:\Python26\tcl\tk8.5 --- <type 'unicode'>
TCL_LIBRARY --- C:\Python26\tcl\tcl8.5 --- <type 'unicode'>

很奇怪,所以的环境变量的值的类型都是string,唯独TK_LIBRARY和TCL_LIBRARY。后来再网上google了一下,原来这是python的一个bug,这里给出一个链接http://bugs.python.org/issue6906。

可以选择升级python,也自己手动地去打patch。diff文件地址是http://bugs.python.org/file15335/FixTk.diff。

  • 收藏

    多个标签使用逗号 , 隔开,最多三个

    推荐标签: python TypeError 待读
  • 粉丝: 3 博客数: 4 共码了 624 字
评论(0

尚无网友评论

微信分享