2

I am looking to convert the html url into ansible uri module, when i load the url in browser it gives results, but from uri module i am getting errors

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

Ansible uri module:-

      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

I am getting this error:-

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",

Please help

rocknrollaki
  • 75
  • 1
  • 4
  • 11

1 Answers1

1

I suspect the problem is that your URL contains spaces (), which aren't valid URL characters. If I run your code against a sample web server, I see the following error after the uri module has successfully negotiated an SSL connection:

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"}

Spaces in a URL should be encoded as + or as %20, so you could write your URL like this:

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

Or like this:

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

Or, if the query is valid without spaces, just write:

https://rally1.rallydev.com/slm/webservice/v2.0/user?query=(FirstName="test1")&fetch=true
larsks
  • 277,717
  • 41
  • 399
  • 399