将htmlurl转换成uri模块ansible

Convert html url into uri module ansible

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

我的URL:- https://rally1.rallydev.com/slm/webservice/v2.0/user?query=(FirstName = 测试 1)&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",

请帮忙

我怀疑问题是您的 URL 包含空格 (</code>),它们不是有效的 URL 字符。如果我 运行 你的代码针对示例 Web 服务器,我在 <code>uri 模块成功协商 SSL 连接后看到以下错误:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: http.client.InvalidURL: URL can't contain control characters. '/slm/webservic e/v2.0/user?query=(FirstName = "test1")&fetch=true' (found at least ' ') fatal: [localhost]: FAILED! => {"changed": false, "content": "", "elapsed": 0, "msg": "Status code was -1 and not [200]: An unknown error occurred: URL can't contain control characters. '/slm/webservice/v2.0/user?query=(FirstName = \"test1\")&fetch=true' (found at least ' ')", "redirected": false, "status": -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