简体   繁体   English

不明白为什么会出现这个 NameError: name 'null' is not defined 异常

[英]Don't understand why this NameError: name 'null' is not defined exception occurs

I'm testing a new code and I'm getting the error below.我正在测试新代码,但出现以下错误。 If I change the field "name: null" for something like "name: abc" it works.如果我将字段“名称:null”更改为“名称:abc”之类的内容,它就会起作用。 Any idea?任何的想法? How I can skip/workaround this "null" issue?我如何跳过/解决这个“空”问题?

Traceback (most recent call last):
  File "<string>", line 3, in <module>
NameError: name 'null' is not defined

Here's my code:这是我的代码:

data = [{"id": 111,
         "description": "",
         "name": null,
         "name_with_namespace": "Zzzz",
         "path": "Zzzz"
         },
        {"id": 222,
         "description": "",
         "name": "xp-demo-gradle",
         "name_with_namespace": "xp-demo-gradle",
         "path": "xp-demo-gradle"
         }]
for request in data:
    lista = []
    request["id"]
    paragraph = "id: " + str(request["id"]) + "; Path: " + request["path"] + "; Name: " + request["name"]
    artifact = {
        "requested_by": "RequestFetcher",
        "argument": {
            "topic": {
                "id": 2
                },
            "key": str(request["id"]),
            "title": "ID " + str(request["id"]),
            "text": paragraph,
            "cached": True,
            "_links": [
                {
                    "href": "https://gitlab.local.com/api/v4/projects/" + str(request["name"]),
                    "rel": "self",
                    "method": "GET"
                    }
                ],
            }
        }
    lista.append(artifact)
    print(lista)

null is not a keyword in Python. null不是 Python 中的关键字。 You should either make it a string (eg 'name': 'null' ) or use None instead您应该将其设为字符串(例如'name': 'null' )或使用None代替

I modified the script to use the json URL instead of add the data directly into the script and then it worked fine.我修改了脚本以使用 json URL 而不是将数据直接添加到脚本中,然后它运行良好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 不明白为什么会收到错误“ NameError:未定义名称&#39;raw_input&#39;” - Don't understand why am getting error “NameError: name 'raw_input' is not defined” 不明白为什么此TypeError:必须是str,而不是float异常发生 - Don't understand why this TypeError: must be str, not float exception occurs 不明白为什么此AttributeError会在for循环中发生 - Don't understand why this AttributeError occurs in for loop 为什么会出现“NameError: name 'draw_Objects' is not defined” - Why “NameError: name 'draw_Objects' is not defined” occurs 不明白为什么会发生此“ OverflowError:Python int太大而无法转换为C long”的异常 - Don't understand why this “OverflowError: Python int too large to convert to C long” exception occurs 我不知道为什么我收到错误:NameError: name &#39;changeRate&#39; is not defined - I don't know why I am getting the error: NameError: name 'changeRate' is not defined 不明白为什么我会收到一个变量的 NameError - Don't understand why I'm getting a NameError for a variable 我不明白为什么我的游戏会抛出NameError - I don't understand why a NameError is thrown in my game 不明白为什么在将 int 转换为 float 的代码中会出现 IndentationError - Don't understand why an IndentationError occurs in this code that converts int to float 不明白为什么ValueError:无法解码JSON对象 - Don't understand why ValueError: No JSON object could be decoded occurs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM