{"action":"opened","issue":{"url":"https://api.github.com/repos/AlienVault-Labs/OTX-Python-SDK/issues/18","repository_url":"https://api.github.com/repos/AlienVault-Labs/OTX-Python-SDK","labels_url":"https://api.github.com/repos/AlienVault-Labs/OTX-Python-SDK/issues/18/labels{/name}","comments_url":"https://api.github.com/repos/AlienVault-Labs/OTX-Python-SDK/issues/18/comments","events_url":"https://api.github.com/repos/AlienVault-Labs/OTX-Python-SDK/issues/18/events","html_url":"https://github.com/AlienVault-Labs/OTX-Python-SDK/issues/18","id":180467694,"number":18,"title":"Search queries are not URL encoded","user":{"login":"alaa-ali","id":6810882,"avatar_url":"https://avatars.githubusercontent.com/u/6810882?v=3","gravatar_id":"","url":"https://api.github.com/users/alaa-ali","html_url":"https://github.com/alaa-ali","followers_url":"https://api.github.com/users/alaa-ali/followers","following_url":"https://api.github.com/users/alaa-ali/following{/other_user}","gists_url":"https://api.github.com/users/alaa-ali/gists{/gist_id}","starred_url":"https://api.github.com/users/alaa-ali/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alaa-ali/subscriptions","organizations_url":"https://api.github.com/users/alaa-ali/orgs","repos_url":"https://api.github.com/users/alaa-ali/repos","events_url":"https://api.github.com/users/alaa-ali/events{/privacy}","received_events_url":"https://api.github.com/users/alaa-ali/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-10-01T17:04:20Z","updated_at":"2016-10-01T17:04:20Z","closed_at":null,"body":"If I try to run a search against `/api/v1/search/pulses` with spaces in the query, I get a Bad Request:\r\n\r\n```python\r\n>>> otx.search_pulses('phpMyAdmin honeypot logs for 2016-10-01')\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\n  File \"OTXv2.py\", line 293, in search_pulses\r\n    return self._get_paginated_resource(search_pulses_url, max_results=max_results)\r\n  File \"OTXv2.py\", line 317, in _get_paginated_resource\r\n    json_data = self.get(next_page_url)\r\n  File \"OTXv2.py\", line 79, in get\r\n    raise BadRequest(\"Bad Request\")\r\n\r\nOTXv2.BadRequest: 'Bad Request'\r\n```\r\n\r\nThis is because the query in the `search_pulses` method is not URL encoded, so it tries to GET something like this: `https://otx.alienvault.com/api/v1/search/pulses?q=phpMyAdmin honeypot logs for 2016-10-01&`.\r\n\r\nTo fix this we can use `urllib.quote_plus` for Python 2 (or `urllib.parse.quote_plus()` for Python 3) to properly encode our query.\r\n\r\n```python\r\n>>> import urllib\r\n>>> urllib.quote_plus('phpMyAdmin honeypot logs for 2016-10-01')\r\n'phpMyAdmin+honeypot+logs+for+2016-10-01'\r\n```\r\n\r\nSo a quick fix would be to update the `q=query` in the `search_pulses` method to `q=urllib.quote_plus(q)`, like so:\r\n\r\n```python\r\ndef search_pulses(self, query, max_results=25):\r\n        search_pulses_url = self.create_url(SEARCH_PULSES, q=urllib.quote_plus(q), page=1, limit=20)\r\n        return self._get_paginated_resource(search_pulses_url, max_results=max_results)\r\n\r\nI'm not sure if this is the norm in APIs, but wouldn't it make sense to update your python API module to do the URL encoding? If you're expecting the user to do it, then maybe mention that under the API module documentation?"}}
{"actor":{"display_login":"alaa-ali"}}