-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Method not Allowed on API #2238
Comments
Hello, @sikaili99! I'm here to help you with any questions or issues you have. Whether it's solving bugs, answering questions, or becoming a contributor, I'm here to assist you while waiting for a human maintainer. The "Method Not Allowed" error occurs because the API endpoint you are trying to access does not support the POST method. Here are a few steps to resolve this issue:
Here is the corrected code: import requests
class LangflowHandler:
BASE_API_URL = "http:https://localhost:7860/api/v1/run"
def __init__(self, flow_id: str = "34c1d9f8-0d82-4755-b4fa-1cdbe44de00c", tweaks: dict = None, api_key: str = "your_api_key"):
self.flow_id = flow_id
self.tweaks = tweaks if tweaks is not None else {}
self.api_key = api_key
def run_flow(self, message: str) -> dict:
"""
Run a flow with a given message and optional tweaks.
:param message: The message to send to the flow
:return: The JSON response from the flow
"""
api_url = f"{self.BASE_API_URL}/{self.flow_id}"
payload = {"inputs": {"text": message}}
headers = {
"Content-Type": "application/json",
"x-api-key": self.api_key
}
if self.tweaks:
payload["tweaks"] = self.tweaks
response = requests.post(api_url, json=payload, headers=headers)
return response.json() And the usage: async def get_langflow_response(self, message):
langflow_handler = LangflowHandler()
response = await sync_to_async(langflow_handler.run_flow)(message)
return response Make sure to replace |
Please remove the double slash in the BASE_API_URL. |
I am making a post request to the API, and I am getting method not allowed. Here is the code I am using.
What am I doing wrong?
And I am using the run_flow method like this
The text was updated successfully, but these errors were encountered: