Issue with file model download()
Closed this issue · 11 comments
Hello,
Currently when trying to use the file.download method on the file model I'm getting the following:
MendeleyApiException: The Mendeley API returned an error (status: 400, message:
InvalidArgument
Only one auth mechanism allowed; only the X-Amz-Algorithm query parameter, Signature query string parameter or the Authorization header should be specifiedAuthorizationBearer MSwxNDIwODY0MTgzMzk5LDI2NTAxNjkxLDEwMjgsYWxsLCxHcDBlenRJU3dpMFR2WFllN2hSc3FTZXQ2UkE3C648160ABEAE54FFe/e5FSQ8t91QOHG2FIzJhO1C9uC1ZvXoqZuBsG9EmBycyGsgIgZFVJqmVduF+SD)
All other queries work fine.
Please let me know what I may be doing wrong.
Thanks!
Actually this same error seems to result when just trying to get the file using file.get(id). I am however able to get to the file using files.iter().
This could be due to psf/requests#1885. Please could you confirm which version of requests you're using (that issue was fixed in 2.3.0)?
I think the files.get(id) method shouldn't be there, and I'm not sure how it could produce that error - please could you post a code snippet?
Per the setup.py
./setup.py: 'requests==2.4.3', ./setup.py: 'requests-oauthlib==0.4.2',
Actually installed
mendeley-python-sdk $> sudo pip freeze|grep requests requests==2.4.3 requests-oauthlib==0.4.2
Seems to be OK. Please could you post the code that's causing you to hit this?
>>> token = {u'access_token': u'', u'expires_in': 3600, u'expires_at': 2417043803.401911, u'token_type': u'bearer', u'scope': [u'all'], u'refresh_token': u'>'}
>>> from mendeley import Mendeley
>>> from mendeley.session import MendeleySession
>>> from django.conf import settings
>>> mendeley = Mendeley(settings.MENDELEY_CLIENT_ID, settings.MENDELEY_SECRET, settings.MENDELEY_REDIRECT_URI)
>>> mendeley_client = MendeleySession(mendeley, token)
>>> for mendeley_file in mendeley_client.files.iter():
... print mendeley_file.id, mendeley_file.file_name
...
620f1eb2-ce7d-8443-70b3-1dd9cd340fed 2001-Multiple_GlnAsn-rich_prion_domains_confer_susceptibility_to_induction_of_the_yeast_PSI()_prion..pdf
7f4d6157-a834-8909-3198-cfda092d120b 2013-Focal_Delivery_of_AAV21-transgenes_Into_the_Rat_Brain_by_Localized_Ultrasound-induced_BBB_Opening..pdf
3ff83372-e3a4-89bd-5bff-6031945a2f2d 2012-Little_things_on_which_happiness_depends_microRNAs_as_novel_therapeutic_targets_for_the_treatment_of_anxiety_and_de.pdf
01f8a9c4-95f4-8bd9-66c6-83361e422f4b 2012-Lentiviral_vectors_encoding_short_hairpin_RNAs_efficiently_transduce_and_knockdown_LINGO-1_but_induce_an_interferon.pdf
30c07c34-90a5-4f69-1828-4f18d19d434d 2014-Nanomicro_and_spectroscopic_approaches_to_food_pathogen_detection..pdf
2b2d4b6b-9802-6821-5452-b4e69ef7fb49 2011-Segment-specific_overexpression_of_redoxins_after_renal_ischemia_and_reperfusion_protective_roles_of_glutaredoxin_2.pdf
19f06c70-ba12-d65f-3e63-8fd1c1b94bd9 2003-glatiramer_acetate_in_the_management_of_multiple_sclerosis.pdf
75516e8f-c315-9a37-748f-5d83a8916769 2011-Hallmarks_of_cancer_the_next_generation..pdf
77f4e4c1-d43a-6a5b-0f5a-3315c4f97867 2011-Pivotal_role_of_dermal_IL-17-producing__T_cells_in_skin_inflammation..pdf
04d97578-bbdb-40d3-2aa3-95d881ca7479 2014-Greens_function_on_lattices.pdf
366e33f9-900b-5e97-506d-242c8f030173 2014-Simplex_and_Polygon_Equations.pdf
56db6dab-d6b5-8b1d-00a7-18ec1dceda31 Whole_genome_mapping_of_5_RNA_ends_in_bacteria_by_tagged_sequencing__A__comprehensive_view_in_Enterococcus_faecalis.pdf
3fdd821b-791d-949b-24af-6aaaa76f0029 Selectivity_filter_gate_versus_voltage-sensitive_gate_A_study_of__quantum_probabilities_in_the_Hodgkin-Huxley_equation.pdf
4bfa4956-79e5-9621-2f76-8daf31570047 Development_stages_of_the_rope_human_intestinal_parasite.pdf
1f6e17bd-087d-9f63-2b5b-9fbaf9cf0731 2014-Epigenetic_Dynamics_of_Cell_Reprogramming.pdf
47e2ee7e-0376-2f2d-0116-4466eb9fd1ed 2014-An_application_of_bole_surface_growth_model_a_transitional_status_of_-32_rule.pdf
078bddfe-9e41-f4d5-49fb-94ae97e38ead 2014-Risking_Your_Life_without_a_Second_Thought_Intuitive_Decision-Making_and_Extreme_Altruism.pdf
3ad6b08f-1674-e387-14ba-fb3a23d2a347 2014-A_General_and_Enantioselective_Approach_to_Pentoses_A_Rapid_Synthesis_of_PSI-6130_the_Nucleoside_Core_of_Sofosbuvir.pdf
6b15cad9-73c4-ffe3-3147-0d61c3d31b47 2014-A_life_in_electrochemistry..pdf
30e94906-933a-f483-09a6-1994d4c02f43 2013-Fifty_years_fused_to_lac..pdf
3633363f-5d98-ae29-0000-98251be846d1 2013-Polymorphism_and_the_Predictability_of_Evolution_in_Fisher__s_Geometric_Model.pdf
3f7c949f-91bf-6627-558b-edda1c419a63 Explaining_temporal_trends_in_annualized_relapse_rates_in_placebo_groups_of_randomized_controlled_trials_in_relapsing_mu.pdf
>>> mendeley_file = mendeley_client.files.get('3f7c949f-91bf-6627-558b-edda1c419a63')
CPython/2.7.6 Linux/3.13.0-29-generic'}
Traceback (most recent call last):
File "", line 1, in
File "build/bdist.linux-x86_64/egg/mendeley/resources/files.py", line 30, in get
return super(Files, self).get(id)
File "build/bdist.linux-x86_64/egg/mendeley/resources/base.py", line 57, in get
rsp = self._session.get(url, headers={'Accept': obj_type.content_type})
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 395, in get
return self.request('GET', url, **kwargs)
File "build/bdist.linux-x86_64/egg/mendeley/session.py", line 102, in request
raise MendeleyApiException(rsp)
MendeleyApiException: The Mendeley API returned an error (status: 400, message:
InvalidArgument
Only one auth mechanism allowed; only the X-Amz-Algorithm query parameter, Signature query string parameter or the Authorization header should be specifiedAuthorizationBearer MSwxNDIxMDg4OTg0NDgxLDI2NTAxNjkxLDEwMjgsYWxsLCxYUW5UbmdyWGRoQ2dEMmMzRFVMZHloRkhhcjQE8DF4697560C4054sU+3kXH95VH1jzr1CmtPa2XiotWH9LFOGLQTxTwavQgWUybT8KdIwSJ7pG6hTxzH)
For download (taking last file from above iter()):
>>> mendeley_file.download("/tmp")
Traceback (most recent call last):
File "", line 1, in
File "build/bdist.linux-x86_64/egg/mendeley/models/files.py", line 51, in download
rsp = self.session.get('/files/%s' % self.id, stream=True)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 395, in get
return self.request('GET', url, **kwargs)
File "build/bdist.linux-x86_64/egg/mendeley/session.py", line 102, in request
raise MendeleyApiException(rsp)
MendeleyApiException: The Mendeley API returned an error (status: 400, message:
InvalidArgument
Only one auth mechanism allowed; only the X-Amz-Algorithm query parameter, Signature query string parameter or the Authorization header should be specifiedAuthorizationBearer MSwxNDIxMDg4OTg0NDgxLDI2NTAxNjkxLDEwMjgsYWxsLCxYUW5UbmdyWGRoQ2dEMmMzRFVMZHloRkhhcjQ969BD336B76F3804qYGNxfXqlwHqUOd38rfzaKfJ1rJwXhH0j5zA886bzjxX4eBlvpWXXDNF93UGkfGR)
Will take a look later, but please be careful not to post your access and refresh tokens.
Thank you!
The first of those methods (mendeley_client.files.get(id)
) doesn't work - it'll be removed in a future SDK release. The download
method on the file model is the supported way to do this.
That said, I can't see why this wouldn't work for you. I've run the following:
for mendeley_file in mendeley_client.files.iter():
mendeley_file.download('/tmp')
which downloads all of my files to /tmp. Does that work for you?
Does that really work for you?
I get
MendeleyApiException: The Mendeley API returned an error (status: 400, message:
InvalidArgument
Only one auth mechanism allowed; only the X-Amz-Algorithm query parameter, Signature query string parameter or the Authorization header should be specifiedAuthorizationBearer 6B2DE3D4FC8BF4F1lidxzEmKcUFFJVAgm7w3Sp32Rhlw2CW0jy0jj+sAj0uZwFwJLVHmuvYkUK38EDCYo0vJaQKKJ3M=)
Very odd. Please could you post the full output from pip freeze
, and let me know your Python version? It might help if you could try in a new virtualenv too.
Chameleon==2.6.1 Cheetah==2.4.4 Django==1.6.5 Flask==0.10.1 Jinja2==2.7.3 Landscape-Client==14.01 MarkupSafe==0.23 MySQL-python==1.2.3 PAM==0.4.2 Pillow==2.5.3 PyJWT==0.3.2 PyYAML==3.11 Pyzotero==1.1.0 SOAPpy==0.12.0 SecretStorage==2.0.0 South==0.7.6 Twisted-Core==13.2.0 Twisted-Names==13.2.0 Twisted-Web==13.2.0 VerbalExpressions==0.0.1 Werkzeug==0.9.6 amqp==1.4.6 anyjson==0.3.3 apt-xapian-index==0.45 argcomplete==0.6.3 argh==0.25.0 argparse==1.2.1 arrow==0.4.4 beautifulsoup4==4.1.3 billiard==3.3.0.18 biopython==1.62 boto==2.8.0 box==0.45.0 box.py==1.2.8 boxpython==1.0.5 bzr==2.7.0dev1 bzr-builddeb==2.8.6 celery==3.1.9 certifi==14.05.14 chardet==2.0.1 citeproc-py==0.3.0 cloud-init==0.7.5 colorama==0.2.5 configobj==4.7.2 distro-info==0.12 django-celery==3.1.9 django-chronograph==0.3.2.dev django-jsonfield==0.9.13 django-registration==0.8 django-s3-folder-storage==0.2 django-sslserver==0.14 django-storages==1.1.8 django-supervisor==0.3.2 django-tinymce==1.5.2 django-tools==0.25.1 django.js==0.8.1 dnspython==1.11.1 dropbox==2.2.0 feedparser==5.1.3 fpconst==0.7.2 future==0.14.1 gbp==0.6.9 google-api-python-client==1.3.1 html5lib==0.999 httplib2==0.9 itsdangerous==0.24 jsonpatch==1.3 jsonpointer==1.0 keyring==3.5 kombu==3.0.21 launchpadlib==1.10.2 lazr.restfulclient==0.13.3 lazr.uri==1.0.3 lptools==0.2.0 lxml==3.3.3 meld3==1.0.0 memoized-property==1.0.2 mendeley==0.2.5 mongodbforms==0.2.2 mongoengine==0.8.3 nameparser==0.3.3 nose==1.3.0 oauth==1.0.1 oauth2==1.5.211 oauth2client==1.4.4 oauthlib==0.7.2 paramiko==1.10.0 path.py==3.0.1 pathtools==0.1.2 poster==0.8.1 prettytable==0.7.2 pyGravatar==0.0.5 pyOpenSSL==0.13 pyasn1==0.1.7 pyasn1-modules==0.0.5 pycrypto==2.6.1 pycurl==7.19.3 pydns==2.3.6 pygobject==3.12.0 pygpgme==0.3 pymongo==2.5 pyserial==2.6 python-apt==0.9.3.5 python-dateutil==1.5 python-debian==0.1.21-nmu2ubuntu2 python-debianbts==1.11 python-magic==0.4.6 python-openid==2.2.5 python-social-auth==0.1.26 pytz==2014.4 pyxdg==0.25 rauth==0.7.0 reportbug==6.5.0 requests==2.4.3 requests-oauthlib==0.4.2 rsa==3.1.4 rtfunicode==1.0 rtfw==0.2 simplejson==3.6.5 six==1.8.0 ssh-import-id==3.21 supervisor==3.1.1 ubuntu-dev-tools==0.153 uritemplate==0.6 urllib3==1.7.1 wadllib==1.3.2 watchdog==0.8.1 wheel==0.24.0 wsgiref==0.1.2 xmltodict==0.8.3 zope.interface==4.0.5
Python 2.7.6
What package should I consider uninstalling and re-installing?
Thanks,
Chris