开发者

Python function gives KeyError but when not trying to write in cell of excel with openpyxl works [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.

This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.

Closed 5 mins ago.

Improve this question

Hey im new to python and I have this code

i=1
teste = "123"
while teste is not None:   #this is to find the last cell filled of 1 column
    teste = ws.cell(row=i, column=1).value
    i = i+1
    print(teste)

y=1
pid = 0 


while y < i-1:  #this will get the policyid(pid) from 1 cell in excel and write in other the result of pid in floor_geral
    pid = ws.cell(row = y, column=5).value
    ws.cell(row = y, column=4).value=floor_geral(pid)
    y = y+1

floor_geral

> def floor_geral(pid):
    api_url = "https://server.jpgstoreapis.com/collection/{}/floor"
    data = requests.get(api_url.format(pid)).json()
    floor = data["floor"] / 1000000

    return floor

This give me this error:

Traceback (most recent call last):
  File "c:\Users\1\Desktop\JPG Wallet\Pool.pm\poolpm2.py", line 53, in <module>
    teste = floor_geral(pid)
            ^^^开发者_Python百科^^^^^^^^^^^^^
  File "c:\Users\1\Desktop\JPG Wallet\Pool.pm\funções.py", line 10, in floor_geral
    floor = data["floor"] / 1000000
            ~~~~^^^^^^^^^
KeyError: 'floor'

Any ideas what it could be? I don´t know if the title was the best and if the post is well done but I'm new to programming and stackoverflow. Any advices?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜