OSError:[WinError 6]句柄是无效的硒+ argparse

时间:2020-09-29 19:35:53

标签: python python-3.x selenium subprocess argparse

操作系统:Windows 10 python:3.8

您好,我知道有多个版本的同一错误here(不符合标准),here(未回答),here(无关且未回答)和已实际注册为python bug here,但找不到解决该问题的解决方案。这段代码可以在我的Macbook Pro上完美运行,并且很可能在linux上没有问题,但是我没有Windows PC来测试它,所以我需要这样做,所以当我通过朋友的PC运行它时(我不会拥有物理访问权限,但我无法自己调试代码)代码将执行并完成预期的所有任务,但是在代码退出时(在浏览器中成功执行所有操作之后),因此发生错误,我将不包括整个代码,仅包括main()__main__防护。

def main(argv):
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--base_url',
        help='start url',
        default='https://opensource-demo.orangehrmlive.com',
    )
    parser.add_argument('--username', help='login username', default='Admin')
    parser.add_argument('--password', help='login password', default='admin123')
    parser.add_argument('--name', help='employee name field', required=True)
    parser.add_argument('--leave_type', help='leave type field', required=True)
    parser.add_argument('--from_date', help='from date field', required=True)
    parser.add_argument('--to_date', help='to date field', required=True)
    parser.add_argument('--partial_days', help='partial days field', default='None')
    parser.add_argument(
        '--comment', help='assign leave comment', default='- Not required -'
    )
    parser.add_argument('--logout', help='logout after ', type=int, default=1)
    cli_args = parser.parse_args(argv)
    logger = get_logger()
    driver = login(cli_args.base_url, logger, cli_args.username, cli_args.password)
    submit_leave_form(
        driver,
        logger,
        cli_args.name,
        cli_args.leave_type,
        cli_args.from_date,
        cli_args.to_date,
        cli_args.partial_days,
        cli_args.comment,
        cli_args.logout,
    )


if __name__ == '__main__':
    main(sys.argv[1:])

错误:

DevTools listening on ws://127.0.0.1:57815/devtools/browser/66dd41c3-c3c9-455e-9a84-4347b146e562
2020-09-30 18:19:39,395 API Extractor: WARNING Overlapping dates for Jasmine Morgan
2020-10-19 | 2020-10-20 | 2020-10-21 | 2020-10-22 | 2020-10-23
Exception ignored in: <function Popen.__del__ at 0x03727F58>
Traceback (most recent call last):
  File "C:\Users\Ghandour\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 945, in _del_
    self._internal_poll(_deadstate=_maxsize)
  File "C:\Users\Ghandour\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1344, in _internal_poll
    if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0:
OSError: [WinError 6] The handle is invalid

0 个答案:

没有答案