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

Replace httpx usage in synchronous OptimadeClient with requests #1536

Merged
merged 2 commits into from
Feb 28, 2023

Conversation

ml-evs
Copy link
Member

@ml-evs ml-evs commented Feb 27, 2023

Bit of a last minute patch before the tutorials... it seems like we don't handle the case of getting IP banned from an API (which may well happen!) when the client is in non-async mode --- fix this for now by adding a very general exception handler to the request.

ALSO: client hangs even in sync mode within Jupyter notebooks.

The cause of this is that at some point httpx removed support for non-async code altogether, even in the sync client. The fix is to just defer to requests at this point. That is what is implemented in this PR, which now allows the client to be properly used within Jupyter/Colab.

Unfortunately I am going to have to merge and release without a review, given that the tutorial is in about 12 hours... I'm pretty confident that this is working well though and I was able to update the testing harness with only a couple of lines.

Closes #1527 and closes #1195 (for now -- async still doesn't work inside a jupyter notebook but at least it now runs).

@ml-evs ml-evs force-pushed the ml-evs/tweak_client branch from 0a5e65f to 4078417 Compare February 27, 2023 20:54
@ml-evs ml-evs changed the title Add very general exception handling for non-async client Replace synchronous httpx client with requests Feb 27, 2023
@ml-evs ml-evs added the client Issues/PRs relating to the OPTIMADE client. label Feb 27, 2023
@ml-evs ml-evs force-pushed the ml-evs/tweak_client branch 2 times, most recently from 0323e44 to 619e2dc Compare February 28, 2023 00:19
- Add very general exception handling for client

- Also explicitly force no async when an event loop is running
@ml-evs ml-evs force-pushed the ml-evs/tweak_client branch from 619e2dc to afa2ce9 Compare February 28, 2023 00:23
@codecov
Copy link

codecov bot commented Feb 28, 2023

Codecov Report

Merging #1536 (afa2ce9) into master (27f38e7) will decrease coverage by 0.02%.
The diff coverage is 83.33%.

@@            Coverage Diff             @@
##           master    #1536      +/-   ##
==========================================
- Coverage   91.08%   91.07%   -0.02%     
==========================================
  Files          74       74              
  Lines        4533     4538       +5     
==========================================
+ Hits         4129     4133       +4     
- Misses        404      405       +1     
Flag Coverage Δ
project 91.07% <83.33%> (-0.02%) ⬇️
validator 90.96% <77.77%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
optimade/client/client.py 81.96% <82.35%> (-0.04%) ⬇️
optimade/__init__.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@ml-evs ml-evs changed the title Replace synchronous httpx client with requests Replace httpx usage in synchronous OptimadeClient with requests Feb 28, 2023
@ml-evs ml-evs merged commit c997f37 into master Feb 28, 2023
@ml-evs ml-evs deleted the ml-evs/tweak_client branch February 28, 2023 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client Issues/PRs relating to the OPTIMADE client.
Projects
None yet
1 participant