Invalid HTTP method in Traceback: Uvicorn - python

I am using uvicorn 0.11.8 and fastapi 0.61.1. My application is hosted in VPS. When I run the app in local server, such error is not reproducible. It shows correct message 404 Not found for methods not available but I couldn't figure out what is causing this issue in VPS (error in Traceback).

I was getting the same arcane WARNING: Invalid HTTP request received. error with an unhelpful stack trace. I tried all of the environment variable tweaks recommended and none worked (see FastAPI issue #680, uvicorn issue #441).
My issue was that when I was calling my FastAPI microservice I was using https when my microservice did not have HTTPS support. I changed the url from https to http and it started working as expected.
Note that if your service requires HTTPS support you can add HTTPS support.
Also, see the similar post AWS ec2 + uvicorn + fastapi, i get uvicorn error.

Related

Fail to enable Smartsheet webhook (502 Bad Gateway)

Django: 4.0.6
Smartsheet Python SDK: 2.105.1
Ngrok: 3.0.6
I have a Django server running on localhost, forwarded my localhost through Ngrok, have setup a callback route for accepting/responding to the Smartsheet-Hook-Challenge, and created a webhook instance using Python SDK. However, when I try to enable my webhook by running the following (documented here):
Webhook = smartsheet_client.Webhooks.update_webhook(webhook_id,smartsheet_client.models.Webhook({'enabled': True}))
Ngrok immediately returns 502 bad gateway, and my webhook instance's disabledDetails attribute becomes Request returned HTTP status code 502 (ref id: wtegm9). And I have no clue what's the cause of this 502.
PS: While I'm writing this question, I was able to successfully enable my webhook using cURL command, so I can go ahead and start working. But enabling the same webhook instance with update_webhook python method still gives 502. Since updating webhook with cURL worked, could it be a bug in the Python SDK method itself?
I would suspect that an issue with Ngrok is causing the 502 error and not a problem with the Smartsheet SDK. A Google search for http 502 bad gateway ngrok returns lots of info about 502 errors with Ngrok, including this Stack Overflow post which contains multiple widely approved answers:
Ngrok errors '502 bad gateway'
I'd start there, if I were you.

Istio - Gunicorn - Python getting 503 upstream connect error or disconnect/reset before headers. reset reason: connection failure

I am running a Istio setup where my python flask service running behind gunicorn.
when debugging the logs from the service, the flask service successfully execute the api call while the calling client is receiving 503 error from the rest call. I suspect this might be some issue with side car proxy or gunicorn server where it is processing the request.
Also, I am hitting the service directly from another pod in the namespace and hence not going through ingress gateway and virtualservice
In my case it was the SSL between Google Front End (ILB) and Istio service mesh. Somehow the connection between GFE and Istio gateway over TLS was not reliable. I converted that to HTTP from HTTP2(https) and it started working.
I will debug later why this https between those 2 was not working but moving HTTP2 to HTTP solved my issue.

How to encrypt (from http to https) while running server with Uvicorn in python

I am stuck in this issue. We are using LDAP over http server using Fastapi framework that runs with uvicorn. I get to know about certbot but I am not sure how to use it with uvicorn. Any help would be appreciated.

In Odoo,what's the difference between the http and https when it comes to writing the controllers?There is an error

I have wirtten a controllers in an Odoo module.There is no problem using postman to test the interface in the debug environment based on http.However,there is some problem using postman to test the interface in the production environment based on https.
Python version 2.7.12
Odoo version 10.0
werkzeug version 0.11.11
Here is my code.Please help me,thank you.
Production environment and the protocol is https.
controllers.py
# -*- coding:utf-8 -*-
from odoo.http import Controller
from odoo.http import route
from odoo.http import request
class PhotoPruner(Controller):
#route('/<string:type>/photo/size/<int:record_id>', type='http', auth='none', methods=['GET'], csrf=False)
def get_info(self, **kwargs):
type = kwargs.get('type')
record_id = kwargs.get('record_id')
return 'ok'
postman test
log error info
Debug environment and the protocol is http
There is no problem.
I receive the 'ok' when I get the http://127.0.0.1/task/photo/size/146
Odoo routing supports two type of requests, http and json. you are getting error on production probably because of using https which is a type not even supported. When you are using web servers nginx or apache in front of your Odoo application and reverse proxy to Odoo application, you are probably using http protocol between webserver and application communication. Check the proxy_pass of your nginx configuration, probably the reverse proxy is http://127.0.0.1:8069 (if you are nginx, or respective apache virtual host configuration line).
For more information about Odoo web controllers, please refer to the official documentation of Odoo, it is specifically mentioned that request type can be http or json.

Istio egress gives "upstream connect error or disconnect/reset before headers" errors from python micro-service

When I am running a Python micro-service in a dockerized or kubernetes container it works just fine. But with Istio service mesh, it is not working.
I have added ServiceEntry for two of my outbound external http apis. It seems I can access the url content form inside the container using curl command which is inside service mesh. So, I think the service entries are fine and working.
But when I try from the micro-service which uses xml.sax parser in Python, it gives me the upstream connect error or disconnect/reset before headers though the same application works fine without Istio.
I think it is something related to Istio or Envoy or Python.
Update: I did inject the Istio-proxy side-car. I have also added ServiceEntry for external MySQL database and mysql is connected from the micro-service.
I have found the reason for this not working. My Python service is using xml.sax parser library to parse xml form the internet, which is using the legacy urllib package which initiate http/1.0 request.
Envoy doesn't support http/1.0 protocol version. Hence, it is not working. I made the workaround by setting global.proxy.includeIPRanges="10.x.0.1/16" for Istio using helm. This actually bypass the entire envoy proxy for all outgoing connections outside the given ip ranges.
But I would prefer not to globally bypass Istio.

Categories

Resources