eve-val/evelink — pull request #172 by flexd (2014-07-11 12:50:24+00:00)
Title: Fix: Proper usage of requests

After CCP restarted the application pool today, I began experiencing issues with evelink.

Adding some debug printing of the content revealed that CCP was returning a HTTP 411 (we should probably catch that, and other HTTP errors!), which means either we need to send data chunked, or have a content-length.

Some quick investigating later I found this comment related to a previous issue https://github.com/kennethreitz/requests/issues/223#issuecomment-2934177

Here he says:

`params` is used for query url parameters. `data` is used for body data.

Fixing this on line 326 of api.py solved the problem entirely :-)

In the future we should really catch possible HTTP exceptions and not just blindly pass data to the XML parser!

Below is the error I got.

```python
$ python -m cron.transaction_import
DEBUG:evelink.api:Calling eve/CharacterID with params={'names': 'This is alt'}
DEBUG:evelink.api:POSTing request
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): api.eveonline.com
DEBUG:evelink.api:Response:

Length Required

Length Required

HTTP Error 411. The request must be chunked or have a content length.

Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/kristoffer/code/eve/cron/transaction_import.py", line 40, in
charid = eve.character_id_from_name(eve_character)
File "/home/kristoffer/.virtualenvs/eve/local/lib/python2.7/site-packages/evelink/eve.py", line 139, in character_id_from_name
api_result = self.character_ids_from_names([name])
File "/home/kristoffer/.virtualenvs/eve/local/lib/python2.7/site-packages/evelink/api.py", line 462, in wrapper
kw['api_result'] = client.api.get(self.path, params=params)
File "/home/kristoffer/.virtualenvs/eve/local/lib/python2.7/site-packages/evelink/api.py", line 251, in get
tree = ElementTree.fromstring(response)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1301, in XML
parser.feed(text)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1643, in feed
self._raiseerror(v)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1507, in _raiseerror
raise err
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 49
```