Robot & Requests Python Frameworks ERROR: HTTPError: 401 Client Error: Unauthorized for URL

最近,我在运行 python 脚本来测试 POST API 请求时遇到此错误。

错误:HTTPError:401 客户端错误:URL 未经授权:

奇怪的是,我的脚本在 GET API 请求的相同机制下运行良好。

我仔细检查了我的凭据以确保它们不是原因。我可以通过 SWAGGER & Postman 访问相同的 POST API 并成功执行它们。

我也尝试调试我的脚本,我看到它在到达“POST On Session”代码行时失败了。

    *** Settings ***
library   Requestslibrary
library   Collections
library   Selenium2library

library  String

library  OperatingSystem
library  SSHlibrary
library  JSONlibrary
Resource    ../TestCases/Authentication.robot

*** Variables ***
${base_url}     https://test.test

*** Test Cases ***

TC0002_POST_CatalogLookup
    [Tags]    post

    Create Session    test    ${base_url}    verify=true

    ${RequestBody}=     create dictionary       testSku="string"    testCode="string"
    ${RequestHeader}=   create dictionary       Content-Type=application/json

    ${resp}=      POST On Session     test        /test/test/test/     data=${RequestBody}    headers=${RequestHeader}

    Should Be Equal As Strings    ${resp.status_code}    200
a198911 回答:Robot & Requests Python Frameworks ERROR: HTTPError: 401 Client Error: Unauthorized for URL

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/215.html

大家都在问