Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Robotframework 如何使用“生成oauth 2.0令牌”;“创建客户端Oauth2会话”;机器人框架中的关键字_Robotframework - Fatal编程技术网

Robotframework 如何使用“生成oauth 2.0令牌”;“创建客户端Oauth2会话”;机器人框架中的关键字

Robotframework 如何使用“生成oauth 2.0令牌”;“创建客户端Oauth2会话”;机器人框架中的关键字,robotframework,Robotframework,我得到以下错误: 缺少架构:无效的URL“无”:未提供架构 也许您的意思是?一般来说,最好提供一个完整的示例,其中还包括加载的特定库。在这种情况下,对关键字的快速搜索显示,它很可能是。通过一些小的改动,我得到了一个不同的错误消息,应该是正确的 Token&{head}=Create Dictionary Content-Type=application/x-www-form-urlencoded Create Client Oauth2 Session temp tok

我得到以下错误:

缺少架构:无效的URL“无”:未提供架构


也许您的意思是?

一般来说,最好提供一个完整的示例,其中还包括加载的特定库。在这种情况下,对关键字的快速搜索显示,它很可能是。通过一些小的改动,我得到了一个不同的错误消息,应该是正确的

Token&{head}=Create Dictionary    Content-Type=application/x-www-form-urlencoded
Create Client Oauth2 Session    temp    token_url=https://websec-qa.cable.comcast.com/as/token.oauth2    tenant_id=customerequipmentqa    tenant_secret=ac975251ba4349acbb962955876ec404    base_url=https://ce-service-qa.u1.app.cloud.comcast.net/xnet/ced/1.0/messages    headers=&{head}    verify=${True}
导致

开始测试:oAuth.Question2.TC 20180618 19:40:27.794:信息: &{head}={Content Type=application/x-www-form-urlencoded}20180618 19:40:48.820:失败:ConnectionError:(“连接已中止”, 错误(10054,'现有连接被远程服务器强制关闭 结束测试:oAuth.Question2.TC


下面是我的代码,但是,我得到了400!=二百

Check Webservice
${token_string}=    Set Variable    Bearer    
Create Session    webservice    ${BASE_TOKEN_URL}    verify=${True}
${data}=    Create Dictionary    token_name=customerequipment    grant_type=client_credentials    client_id=customerequipmentqa    client_secret=ac975251ba4349acbb962955876ec404    scope=xnet:customerequipment
${headers}=    Create Dictionary    Content-Type=application/x-www-form-urlencoded
${resp}=    Post Request    webservice    /as/token.oauth2    data=${data}    headers=${headers}
Should Be Equal As Strings    ${resp.status_code}    200
${token}=    evaluate    $resp.json().get("access_token")
${stripped_token}=    Strip String    ${token}
${token_string}=    Catenate    ${token_string}    ${stripped_token}
[Return]    ${token_string}

尝试以下方法:-

*** Keywords ***
Generate Token
    ${token_string}=    Set Variable    Bearer
    create session   my_session     https://qa3-apiv2.xxx.com/oauth2    verify=${True}
    ${data1}=    create dictionary  grant_type=password    client_id=9cde7c7dcf4d47772a068bf24ca0f518657a5f84    client_secret=cf102c871fe20a85c3dfb9d4d114eebccace168b   username=qa3test_admin   password=Password123#
    ${resp}=     Post Request     my_session      /token.php    data=${data1}
    Should Be Equal As Strings  ${resp.status_code}  200
    ${token}=    evaluate    $resp.json().get("access_token")
    Log    ${resp.content}

您需要包含标题才能使其正常工作。例如-“${headers}=Create Dictionary Content Type=application/x-www-form-urlencoded”
*** Keywords ***
Generate Token
    ${token_string}=    Set Variable    Bearer
    create session   my_session     https://qa3-apiv2.xxx.com/oauth2    verify=${True}
    ${data1}=    create dictionary  grant_type=password    client_id=9cde7c7dcf4d47772a068bf24ca0f518657a5f84    client_secret=cf102c871fe20a85c3dfb9d4d114eebccace168b   username=qa3test_admin   password=Password123#
    ${resp}=     Post Request     my_session      /token.php    data=${data1}
    Should Be Equal As Strings  ${resp.status_code}  200
    ${token}=    evaluate    $resp.json().get("access_token")
    Log    ${resp.content}
Create Session   baseUri   https://xxxxxx.xx.xxx/xxx/xx      verify=True
&{params}=  Create Dictionary   client_id=${client_id}   client_secret=${client_secret}   grant_type=${grant_type}
&{headers}=  Create Dictionary   Content-Type=application/json
${resp}=  Post Request  baseUri  /oauth/token    none    none    ${params}  ${headers}
Log to Console  ${resp.json()['access_token']}
Status Should Be 200            ${resp}