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

fix(python): add fallback in case content-length isn't available #95

Merged
merged 3 commits into from
Oct 19, 2020

Conversation

kanadgupta
Copy link
Member

@kanadgupta kanadgupta commented Sep 24, 2020

🧰 What's being changed?

When creating a test app with https://github.com/readmeio/flask-metrics-example, I ran into this error:

Traceback (most recent call last):
  File "~/flask-starter/venv/lib/python3.7/site-packages/readme_metrics/MetricsMiddleware.py", line 68, in __call__
    content_length = int(environ["CONTENT_LENGTH"])
KeyError: 'CONTENT_LENGTH'

Per PEP 3333 definition of CONTENT_LENGTH:

The contents of any Content-Length fields in the HTTP request. May be empty or absent.

TODO

  • Tests

🧪 Testing

Set up https://github.com/readmeio/flask-metrics-example and observe the error.

@kanadgupta kanadgupta added area:python bug Something isn't working labels Sep 29, 2020
This Python code prettifier is... fascinating
@kanadgupta kanadgupta marked this pull request as ready for review October 19, 2020 18:13
@erunion erunion merged commit adf4092 into master Oct 19, 2020
@erunion erunion deleted the python/fix/content-length-fallback branch October 19, 2020 18:16
domharrington pushed a commit that referenced this pull request Apr 19, 2022
* fix(python): add fallback in case content-length isn't available

* fix: use try..catch in case of empty strings, etc

Appears to be the best practice according to this:

http://wsgi.tutorial.codepoint.net/parsing-the-request-post

* chore: black ⚫

This Python code prettifier is... fascinating
@erunion erunion added python Issues related to our Python SDK and removed area:python labels Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Issues related to our Python SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants