【已解决】这个 logging.basicConfig这块代码为何报错?
本帖最后由 鹿小诞 于 2017-5-18 14:25 编辑已解决,我自己写错了。 :L:L:L:L:L:L:L:L:L:L 大家请无视
#coding=utf-8
from selenium import webdriver
import time
import os
import datetime
import logging
import traceback
#测试登录系统是否成功函数
def _Login_(username,password):
#输入用户名密码
driver.find_element_by_name('username').clear()
driver.find_element_by_name('username').send_keys(username)
driver.find_element_by_name('psword').clear()
driver.find_element_by_name('psword').send_keys(password)
driver.find_element_by_name('submitBtn').click()
#验证是否登录成功
time.sleep(10)
currenturl = driver.current_url
if currenturl == "http://10.188.181.74:9082/webnc2-webapp/index-metro2016.html1" :
print("登录成功!")
else:
_WriteLog_(r"E:\自动化测试\test\登录客反.py")
#写入日志函数
def _WriteLog_(filename):
# 构造文件名:basename获取文件名.后缀。splitext分离文件名及后缀名 basenmae+当前时间
logname = os.path.splitext(os.path.basename(filename))[0] + datetime.datetime.now().strftime("%Y%m%D%H%M%S") + ".log"
logging.basicConfig(filename=logname)
s = traceback.format_exc()
logging.error(s)
driver = webdriver.Chrome()
driver.get("http://10.188.181.74:9082/sso-webapp")
#登录系统
_Login_("zhulj","1")
为什么运行了报错:Traceback (most recent call last):File "E:/自动化测试/test/登录客反.py", line 53, in <module> _Login_("zhulj","1")File "E:/自动化测试/test/登录客反.py", line 34, in _Login_ _WriteLog_(r"E:\自动化测试\test\登录客反.py")File "E:/自动化测试/test/登录客反.py", line 41, in _WriteLog_ logging.basicConfig(filename=logname)File "C:\Users\sunl\AppData\Local\Programs\Python\Python36\lib\logging\__init__.py", line 1781, in basicConfig h = FileHandler(filename, mode)File "C:\Users\sunl\AppData\Local\Programs\Python\Python36\lib\logging\__init__.py", line 1030, in __init__ StreamHandler.__init__(self, self._open())File "C:\Users\sunl\AppData\Local\Programs\Python\Python36\lib\logging\__init__.py", line 1059, in _open return open(self.baseFilename, self.mode, encoding=self.encoding)FileNotFoundError: No such file or directory: 'E:\\自动化测试\\test\\登录客反20170505\\18\\17135258.log'
求问不知道哪里出问题了
报错如下:
C:\Users\sunl\AppData\Local\Programs\Python\Python36\python.exe E:/自动化测试/test/登录客反.py
Traceback (most recent call last):
File "E:/自动化测试/test/登录客反.py", line 53, in <module>
_Login_("zhulj","1")
File "E:/自动化测试/test/登录客反.py", line 34, in _Login_
_WriteLog_(r"E:\自动化测试\test\登录客反.py")
File "E:/自动化测试/test/登录客反.py", line 41, in _WriteLog_
logging.basicConfig(filename=logname)
File "C:\Users\sunl\AppData\Local\Programs\Python\Python36\lib\logging\__init__.py", line 1781, in basicConfig
h = FileHandler(filename, mode)
File "C:\Users\sunl\AppData\Local\Programs\Python\Python36\lib\logging\__init__.py", line 1030, in __init__
StreamHandler.__init__(self, self._open())
File "C:\Users\sunl\AppData\Local\Programs\Python\Python36\lib\logging\__init__.py", line 1059, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding)
FileNotFoundError: No such file or directory: 'E:\\自动化测试\\test\\登录客反20170505\\18\\17135258.log' 咋解决的 :victory: 梦想家 发表于 2017-5-18 15:31
咋解决的
strftime("%Y%m%D%H%M%S")这串我给写错了。
页:
[1]