Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request with "custom fields" needs "json" instead of "data" #4

Closed
akej74 opened this issue Apr 5, 2018 · 8 comments

Comments

2 participants
@akej74
Copy link
Contributor

commented Apr 5, 2018

Hi, I had a working Python script running, getting services data from the Elvanto API. Yesterday, I did an update to some modules in my environment and one of these was "requests" (updated to 2.18.4). After this, the ElvantoAPI did not return any info for the "custom fields". ElvantoAPI is 1.4.1.

Example code:

custom_fields = ["series_name", "volunteers"]
connection = ElvantoAPI.Connection(APIKey='xxx')
response = connection._Post("services/getAll", fields=custom_fields)

To get it to work again, I had to to update ElvantoAPI/init.py on line 139 and change "data=kwargs" to "json=kwargs" as follows:

self.data = self.s.post(posturl, json=kwargs) #This is the code that does the actual call

Please let me know if I can do some more tests or more troubleshooting. I suspect the updated request module is the root cause... 2.18.4 is the latest one on PyPi.

@StewPoll

This comment has been minimized.

Copy link
Contributor

commented Apr 5, 2018

I was just running into this issue yesterday myself.

I suspect it's a change with Requests as well, but haven't had time to double check.

Really annoying thing is that originally it was json=kwargs but had to change it here for similar reasons

If you can make the change and test requests 2.18 and 2.17, and see if they both work with the change that would be useful.

@akej74

This comment has been minimized.

Copy link
Contributor Author

commented Apr 6, 2018

I have now tested with requests 2.18.4, 2.17.3, 2.16.5, 2.13.0, 2.12.5 and 2.11.1. All of these fails using "data" but works using "json" for the call. Very strange, maybe the problem is related to some other module that was updated yesterday? It's interesting that you get the same issue in your environment, do you know if you updated some other module yesterday as well?

Here are all my modules currently installed:

aiohttp==3.1.2
altgraph==0.15
async-timeout==2.0.1
attrs==17.4.0
backcall==0.1.0
bleach==2.1.3
certifi==2018.1.18
chardet==3.0.4
click==6.7
colorama==0.3.9
cycler==0.10.0
decorator==4.2.1
ElvantoAPI==1.4.1
entrypoints==0.2.3
future==0.16.0
html5lib==1.0.1
humanize==0.5.1
idna==2.6
idna-ssl==1.0.1
IMDbPY==6.4.1
ipykernel==4.8.2
ipython==6.3.0
ipython-genutils==0.2.0
jedi==0.11.1
Jinja2==2.10
jsonschema==2.6.0
jupyter-client==5.2.3
jupyter-core==4.4.0
jupyterlab==0.31.12
jupyterlab-launcher==0.10.5
kiwisolver==1.0.1
lxml==4.2.1
macholib==1.9
MarkupSafe==1.0
matplotlib==2.2.2
mistune==0.8.3
multidict==4.1.0
nbconvert==5.3.1
nbformat==4.4.0
notebook==5.4.1
numpy==1.14.2
odfpy==1.3.6
pandas==0.22.0
pandocfilters==1.4.2
parso==0.1.1
pefile==2017.11.5
pickleshare==0.7.4
Pillow==5.1.0
prompt-toolkit==1.0.15
psycopg2==2.7.4
Pygments==2.2.0
PyInstaller==3.3.1
pyparsing==2.2.0
pypiwin32==220
PyQt5==5.10.1
pyserial==3.4
python-dateutil==2.7.2
python-docx==0.8.6
pytz==2018.3
pywin32==223
pywinpty==0.5.1
pyzmq==17.0.0
rarbg==1.1.4
RarbgAPI==0.1.1
requests==2.18.4
selenium==3.11.0
Send2Trash==1.5.0
simplegeneric==0.8.1
sip==4.19.8
six==1.11.0
SQLAlchemy==1.2.6
terminado==0.8.1
testpath==0.3.1
tornado==5.0.1
traitlets==4.3.2
urllib3==1.22
virtualenv==15.2.0
wcwidth==0.1.7
webencodings==0.5.1
WMI==1.4.9
yarl==1.1.1
@akej74

This comment has been minimized.

Copy link
Contributor Author

commented Apr 6, 2018

I did a new test with a clean virtual environment (Python 3.6.5) where I only installed ElvantoAPI. This makes no difference, the request only works if I change from "data" to "json".

Here is my minimal environment for reproducing the problem:

certifi (2018.1.18)
chardet (3.0.4)
ElvantoAPI (1.4.1)
idna (2.6)
pip (9.0.3)
requests (2.18.4)
setuptools (39.0.1)
urllib3 (1.22)
@StewPoll

This comment has been minimized.

Copy link
Contributor

commented Apr 9, 2018

A new virtual env will install the most recent version of Requests, so that would be why the clean virtual env is still having the issue.

@akej74

This comment has been minimized.

Copy link
Contributor Author

commented Apr 9, 2018

Hi, I did a test with some older versions of requests (in my virtual env). For all versions I tested (requests 2.18.4, 2.17.3, 2.16.5 and 2.13.0), the API call (with custom fields) only works if using "json=kwargs", not "data=kwargs".

Maybe requests is not the root cause to the problem...?

My test code:

import ElvantoAPI
from pprint import pprint

connection = ElvantoAPI.Connection(APIKey='xxx')
id = 'yyy'

custom_fields = ['songs', 'volunteers']
response = connection._Post("services/getInfo", id=id, fields=custom_fields)
pprint(response)
@StewPoll

This comment has been minimized.

Copy link
Contributor

commented Apr 16, 2018

With their changes to how they handle their dependancies, it may actually be something deeper and in urllib3 or something even further down.

Feel free to do a pull request that makes the change as I'd be more than happy to merge it in and do a new release to pypi

@akej74

This comment has been minimized.

Copy link
Contributor Author

commented Apr 16, 2018

PR submitted!

@StewPoll

This comment has been minimized.

Copy link
Contributor

commented Apr 16, 2018

Closed with #5

@StewPoll StewPoll closed this Apr 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.