Comments (5)
Thanks for looking into it.
If I recall, the intent was that raise_for_status() would raise an exception which would cause a different return code
I've made this repo to show the intent, check out and run venv
and test
targets.
Is this working as intended?
from awscurl.
Thanks for your quick response @okigan. I understand the intention, the main issue with raise_for_status()
is that it raises an exception and will print also print a traceback.
As an example, using awscurl
to call a lambda function url with something like the following:
awscurl -H 'Content-Type: application/json' -X POST -d '{"foo": "bar"}' --service lambda --region us-east-1 https://foo.lambda-url.us-east-1.on.aws/
I may expect to get a non-200 status code if the payload is incorrect. Currently with raise_for_status()
this looks like
{"errors": {"msg": "Some detailed error description"}}
Traceback (most recent call last):
File "/Users/steve/.local/share/virtualenvs/example/bin/awscurl", line 8, in <module>
sys.exit(main())
File "/Users/steve/.local/share/virtualenvs/example/lib/python3.10/site-packages/awscurl/awscurl.py", line 521, in main
inner_main(sys.argv[1:])
File "/Users/steve/.local/share/virtualenvs/example/lib/python3.10/site-packages/awscurl/awscurl.py", line 515, in inner_main
response.raise_for_status()
File "/Users/steve/.local/share/virtualenvs/example/lib/python3.10/site-packages/requests/models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 422 Client Error: Unprocessable Entity for url: https://foo.lambda-url.us-east-1.on.aws/
Whereas this would be more desirable
{"errors": {"msg": "Some detailed error description"}}
If the main intention was to raise a non-zero exit code could I suggest this instead?
print(response.text)
exit_code = 0 if response.ok else 1
return exit_code
from awscurl.
I'm happy to open a PR if you are amenable to that.
from awscurl.
Yes, PR would be great!
I had a quick look at response.ok and looks like it also calls raise_for_status which would still produce the output you'd like to avoid? Something similar to this could get the behavior you are looking for.
Again, thanks for looking into this.
from awscurl.
Thanks @okigan. I have opened a PR in #153 with an explanation of why response.ok
is still sufficient. Thanks for being open to the PR and even more thanks for the very handy tool you've written.
from awscurl.
Related Issues (20)
- Support import as module??? HOT 4
- migrate to src structure
- Credentials issue introduced in 0.27.0 when running on EC2 instance. HOT 7
- Request: Support for Container credentails HOT 2
- v0.28 build failure with Homebrew HOT 2
- How to escape AMP query parameter right? HOT 15
- cryptography-40.0.2 breaks aws cli HOT 2
- Dockerfile should include builder stage
- header 'x-amz-security-token' with None HOT 1
- Strings must be encoded before hashing HOT 8
- "botocore package could not be loaded"
- arm64 image support HOT 8
- awscurl generates an incorrect request signature when user-supplied hostname includes capital letters.
- latest docker images after v0.29 failing on AMD64 HOT 5
- Can you show an example of calling aws curl from using the docker container that returns an error code to the calling process please? HOT 1
- Provide an example for uploading a file to an S3 bucket
- Homebrew package does not install botocore
- [FEATURE] enhance awscurl support create/send multipart POST REST request (from file) HOT 6
- Fail to add filters in API Prometheus query via awscurl in python script HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from awscurl.