1.SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame
場景:運用pandas修改某個序號所對應的key值時出現了該類警告
https://stackoverflow.com/questions/26724378/pandas-settingwithcopywarning
代碼:
df_index = df.loc[index]
df_index[key] = value
修改:
df.loc[index,key] = value
這里的“index”是df數據中序號,“key”是標簽所對應的key,“value”為需要修改的內容,value可以為int、str、以及類對象
2.selenium.common.exceptions.WebDriverException: Message: unknown error: Element is not clickable at point (456, -17)
場景:打開微信公眾號的鏈接之后,將瀏覽器修改為手機模式之后,通過click去點擊的時候提示不可點擊
辦法:設置瀏覽器為最大化之后就可點擊了
3.selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: An invalid or illegal selector was specified
原因:定位方式寫錯了
4.SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
場景:在“ini”為后綴名的文件中寫入的文件路徑
方法:輸入路徑或者網址時用的是反斜杠‘\’導致錯誤,如果用雙正斜杠就好了'//'
5.TypeError: invalid type comparison
場景:使用operator對兩個list進行比價時,出現問題
原因:有一個list是str類型的數據,有一個數int類型的數據
方法:將某一個list里面的數據進行轉換之后在添加到list中然后在進行比較
6.TypeError: 'module' object is not callable
from導入的時候包名寫錯
場景:手動導入包時,因大小寫的關系或者包名重新修改了,導致找不到相應的包
7.TypeError: not all arguments converted during string formatting
print進行輸入時語句上只寫了兩個%s,但是參數卻有多個。
場景:進行輸出時,輸出參數多於了定義的參數
8.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
頁面刷新之后需要重新定位。
場景:執行某一個動作之后,界面重新刷新。此時元素需要重新定義
9.ValueError: Can only compare identically-labeled DataFrame objects
錯誤原因:需要比較的兩個數據類型(即type類型不一致)不一致
出項的場景:
1.兩個pandas對象進行比較時,各自長度不相等出現的錯誤
2.同一個key下面的數據 value 數據 type 不同
10.TypeError: argument of type 'NoneType' is not iterable
錯誤原因:程序運行過快,沒有設置中間變量時導致
出現場景:想獲取df里面的某個值並傳入相應的函數中
weizhi = self.overall[dn.dailyCity()]
dl.setSelectorText(weizhi)
11.ValueError: invalid literal for int() with base 10: '2018-04-05 00:00:00-2018-05-06 23:59:59'
錯誤原因:自己寫的時間戳轉日期的函數時,本應傳入時間戳,而我傳入的是日期格式所以導致這個問題
12.TypeError: expected string or bytes-like object
錯誤原因:拿一個空的數據去執行正則比較。
場景:
my_sql = None,然后運行regular = re.match('^SELECT', my_sql)
13.TypeError: not all arguments converted during string formatting
錯誤原因:數據打印的格式輸入有誤
出現場景:log日志進行輸出時導致
self.log.info( inspect.stack()[0][3] % "%s 公告頁面的tbody不存在" )
修改后:self.log.info( "%s 公告頁面的tbody不存在" % inspect.stack()[0][3] )
14.tuple index out of range
錯誤原因:好像是因為mysql語句指令太長導致,當時同時有多個錯誤。后面沒有進行校驗
15.bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?
錯誤原因:沒有安裝lxml,然后bs4獲取數據之后又使用lxxml進行數據解析然后錯誤錯誤
解決方案:pip install lxml就解決了
16.TypeError: not all arguments converted during string formatting
錯誤原因:time.localtime(status_time)轉換的數據之后不能通過字符串形式進行輸出
場景:pring("時間" + time.localtime(status_time))
17.TypeError: Object of type 'WebElement' is not JSON serializable
錯誤原因:driver通過css_selector來獲取元素時,應該傳入css_selector路徑而我傳入一個int數據
18.local variable 'attribute' referenced before assignment
錯誤原因:局部變量元素attribute沒有函數
場景:EC判斷一個元素是否找到,如果找到就獲取attribute屬性值,沒有知道就返回FALSE。
而當時沒有找到我也去獲取attribute屬性值然后就報錯了,都是復制粘貼的錯誤
19.yaml.scanner.ScannerError: while scanning a block scalar expected a comment or a line break, but found 't'
錯誤原因: 在編寫元素路徑時(thead: > tbody > tr) 多寫了一個冒號,然后報錯
20.ValueError: Unsupported or invalid CSS selector: ">tbody"
錯誤原因:使用bs4爬取數據時,因通過select來查找數據,多寫了>tbody。提示找不到tbody。去掉該tbody即可
21.AttributeError: 'NoneType' object has no attribute 'encoding'
錯誤原因:mysql進行鏈接時,字符集charset沒有設置為utf8而是設置為QQAA導致的。
場景:鏈接數據庫時charset設置有誤
self.connect = pymysql.Connect(
host=host,
port=port,
user=user,
passwd=passwd,
db=db,
charset=charset
)
22.ValueError: I/O operation on closed file.
錯誤原因:使用with open()as file時,在with里面創建參數然后在with外面進行使用
針對with寫入數據一個優化:with open() as file:往csv寫入數據時,每個數據之間都有一個空格。
解決方法: open(newline='')中指定newline參數為空,官方解釋該參數是每個csv之間的分割符
23.http.client.CannotSendRequest: Request-sent
錯誤原因:在接口請求數據時網絡請求太快
解決方法:每個請求之間加個休眠的時間
24.TypeError: 'NoneType' object is not iterable
錯誤i原因:yaml數據為空時,去讀取yaml文件數據
解決方法:在yaml里面隨意寫入一些數據信息
25.KeyError: <module 'project_path' from 'E:\\project_path\\__init__.py'>
報錯的地方: HTMLTestRunner執行多任務的ceses時,出現這類問題。單個cese執行的時候並沒有報錯
錯誤原因: case包命名不規范
方法: 對case的包名進行修改
26.KeyError: 'pass_ticket'
錯誤原因:wxpy框架登陸微信時出現這個錯誤
解決方案:不要使用小號微信或者有異常又或者沒有使用web登錄過的微信號
27.HTMLTestRunner:生成的報告中,“通過”按鈕無法點擊。
原因:運行case時沒有輸出語句
解決方案:每個case都加個log
28.最開始unittest中defaultTestLoader的discover函數中top_level_dir屬性傳入none
多線程運行的時候出現了匪夷所思的錯誤,發現top_level_dir需要傳入項目的起始路徑
discover = unittest.defaultTestLoader.discover(case_path,
pattern=rule,
top_level_dir=CUR_PATH)
對該字段還沒有理解,希望有人給出更好的解釋
日后再更新。。。。。。。。