原文:讀取頁面返回字典值提示錯誤:TypeError: string indices must be integers, not str

路由器get rand key.cgi返回用於后續AES加密的隨機數,該返回值是字典。 如下代碼, print pagetext返回字典 rand key : c d b f c a a bba beaf d da dd cd print pagetext rand key 提示錯誤TypeError: string indices must be integers, not str 解決方法: ...

2014-12-04 12:24 0 17323 推薦指數:

查看詳情

TypeError: string indices must be integers

這個錯誤意思是字符串的下標一定要是整數出這種錯誤有多種可能,最形象直接的就是: 有點pyhton基礎的都知道下標怎么能是字符串’0’,必須是整數0,1,2,3… 才是正確的 第二種是json格式導致的錯誤: 報錯 ...

Tue Mar 31 17:32:00 CST 2020 0 7606
TypeError: list indices must be integers or slices, not str

錯誤如下: 錯誤代碼塊: aa是一組list套dict數據 函數insert接收2個參數,*args,**kwargs 我希望把aa這個list傳給*args, 但在執行程序時卻報了一標題顯示的錯誤 首先是關於*args ...

Tue Aug 27 19:31:00 CST 2019 0 5025
python報錯 TypeError: string indices must be integers

所以在讀取字典的時候,最好先判斷類型,然后再查看它是否已經有這樣的屬性: type(mydict) == type({}) #檢查不是字典 如果是字典,再看看有沒有這樣的屬性:mydict.has_key('mykey') 1、 看看變量是否 ...

Sat Aug 25 03:46:00 CST 2018 0 12675
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM