将HTML网址转换为uri模块ansible

时间:2019-05-27 05:55:25

标签: ansible rally

我希望将html URL转换为ansible uri模块,当我在浏览器中加载url时,它会提供结果,但是从uri模块中却出现错误

我的网址:- https://rally1.rallydev.com/slm/webservice/v2.0/user?query=(FirstName = test1)&fetch = true

Ansible uri模块:-

      uri:
        url: https://rally1.rallydev.com/slm/webservice/v2.0/user?query=(FirstName = "test1")&fetch=true
        user: myusername
        password: mypass
        force_basic_auth: yes
        follow_redirects: all
        return_content: yes
        method: GET
      register: get_data
    - debug: var=get_data

我收到此错误:-

fatal: [localhost]: FAILED! => {"cache_control": "no-cache", "cf_ray": "4dd5a65fea0cba46-ATL", "changed": false, "connection": "close", "content": "<html><body><h1>400 Bad request</h1>\nYour browser sent an invalid request.\n</body></html>\n", "content_type": "text/html", "date": "Mon, 27 May 2019 05:39:42 GMT",

请帮助

1 个答案:

答案 0 :(得分:0)

我怀疑问题在于您的URL包含空格(),该空格不是有效的URL字符。如果我在示例Web服务器上运行您的代码,则uri模块成功协商SSL连接后,会看到以下错误:

  

任务执行期间发生异常。要查看完整的回溯,请使用-vvv。错误为:http.client.InvalidURL:URL不能包含控制字符。 '/ slm / webservic   e / v2.0 / user?query =(FirstName =“ test1”)&fetch = true'(至少找到'')   致命的:[本地主机]:失败! => {“已更改”:false,“内容”:“”,“经过”:0,“ msg”:“状态码为-1而不是[200]:发生未知错误:URL不能包含控件   字符。 '/slm/webservice/v2.0/user?query=(FirstName = \“ test1 \”)&fetch = true'(至少找到'')“,”重定向“:false,”状态“:-1,” url”:“ https://localhost:8080/slm/   webservice / v2.0 / user?query =(FirstName = \“ test1 \”)&fetch = true“}

URL中的空格应为encoded as + or as %20,因此您可以这样写URL:

https://rally1.rallydev.com/slm/webservice/v2.0/user?query=(FirstName+=+"test1")&fetch=true

或者这样:

https://rally1.rallydev.com/slm/webservice/v2.0/user?query=(FirstName%20=%20"test1")&fetch=true

或者,如果查询有效且没有空格,则只需输入:

https://rally1.rallydev.com/slm/webservice/v2.0/user?query=(FirstName="test1")&fetch=true
相关问题