[Python2.7]用phantomjs和selenium遇到错误(TypeError: getaddrinfo() argument 1 must be string or None)


  • 错误:
  File "youku_ckey.py", line 45, in youku_ckey
    driver = webdriver.PhantomJS(executable_path=bce_exec_path,desired_capabilities=desired_capabilities,service_args=service_args)
  File "/home/cyl/lib/python2.7/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 62, in __init__
    desired_capabilities=desired_capabilities)
  File "/home/cyl/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 148, in __init__
    self.command_executor = RemoteConnection(command_executor, keep_alive=keep_alive)
  File "/home/cyl/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 120, in __init__
    port=port)
  File "/home/cyl/lib/python2.7/site-packages/selenium/webdriver/common/utils.py", line 72, in find_connectable_ip
    connectable = is_connectable(port, sockaddr[0])
  File "/home/cyl/lib/python2.7/site-packages/selenium/webdriver/common/utils.py", line 106, in is_connectable
    socket_ = socket.create_connection((host, port), 1)
  File "/home/cyl/lib/python2.7/socket.py", line 554, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
TypeError: getaddrinfo() argument 1 must be string or None
  • 解决:
    (1). 打开 /home/cyl/lib/python2.7/socket.py
    (2). 如错误,定位554行发现
    getaddrinfo的方法,
    打印出来这个位置的数据:
1

发现:
host有一些非string的值,所以需要修改源代码:

2

再次测试,发现成功了~


by 炎隆

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容