python - "ValueError: expected ' : ' after conversion specifier" when trying to authorise on site with x-api-key

标签 python pytest tavern

问题:

  • 当我发送一个 yaml 文件时,我是根据 postman 的情况制作的 要求。我收到错误“ValueError: 转换后预期的 ':' 说明符”以及许多其他错误。这似乎是由于 当我采取这个时,在标题中添加“x-api-key” 错误消失。
---
test_name: Log in

stages:
 - name: Send log in request

    request:
      url: https://myurl.com/auth
      method: POST
      headers:
        Content-Type: application/json
        x-api-key: "<DQDg4lEmau^9{>!Os'mhNP" #Edited this to keep safe but kept the exact same layout
        Authorization: Basic bm90bXlyZWFsZW1haWxAZ21haWwuY29tOnBhc3N3b3JkMTIzCg==

    response:
      status_code: 200
...

预期结果:

  • 能够像我一样向服务器授权并获取 JWT token postman 。

实际结果:

  • 脚本失败并出现许多错误。主要的似乎是我上面列出的,但如果我错了,我可以提供更多。

其他信息:

  • 删除“x-api-key”可以让请求通过,但会返回“Forbidden”,因为我相信这是必需的值。

感谢您的帮助,我已经浏览了 Tavern 上的文档一两个小时,并浏览互联网寻找答案。我是新人,所以我确信这很简单,但任何建议都会很棒。

谢谢!

最佳答案

这是由于引用的“x-api-key”中的大括号造成的。

大括号必须通过写两个代替一个来转义。

例如

x-api-key: "<DQDg4lEmau^9{{>!Os'mhNP"

关于python - "ValueError: expected ' : ' after conversion specifier" when trying to authorise on site with x-api-key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57869136/

相关文章:

python - 根据字符串列的最后一个字母,使用掩码删除 Pandas df 行

python - 在 testinfra 中使用 Ansible 变量

python - pytest 找不到 pytest.fixture_request

python - 关于 yaml 架构验证的错误(此处不允许映射值)是什么意思?

python - tkinter 自动完成小部件小写偏差

python - 将字典列表转换为层次结构

testing - 需要在 .yaml 文件中带上实际日期

Python在具有特定扩展名的目录中获取最新文件

python - 如何解决“PytestDeprecationWarning : pytest. config global is deprecated