I created a public route in Odoo10 with type json and i tried to call it from a API clinet( ARC), i am getting 404 Not found error. I don't know why.
Here is my code
controller.py
# -*- coding: utf-8 -*-
from odoo import http,tools
from odoo.http import request, Response
import requests
class TestURL(http.Controller):
#http.route('/create_lead', type="json", method=['POST'], auth='public', csrf=False)
def createLead(self,**kw):
print('Inside create lead')
// rest of the code here
Here is the response i am getting in api client:
{"jsonrpc": "2.0", "id": null, "error": {"message": "404: Not Found", "code": 404, "data": {"debug": "Traceback (most recent call last):\n File \"/home/user/Projects/odoo-10/odoo/http.py\", line 642, in _handle_exception\n return super(JsonRequest, self)._handle_exception(exception)\n File \"/home/user/Projects/odoo-10/odoo/http.py\", line 1471, in _dispatch_nodb\n func, arguments = self.nodb_routing_map.bind_to_environ(request.httprequest.environ).match()\n File \"/usr/local/lib/python2.7/dist-packages/werkzeug/routing.py\", line 1581, in match\n raise NotFound()\nNotFound: 404 Not Found: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.\n", "exception_type": "internal_error", "message": "404 Not Found: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.", "name": "werkzeug.exceptions.NotFound", "arguments": []}, "http_status": 404}}
Try
#http.route(['/create_lead']...
and check the identation
Related
When I'm trying to pass the API endpoint values in the post API file, KeryError has unfortunately been raised. In the baseapi.ini file, I wrote [API] endpoint = value
Post API file:
import requests
from APIs.payLoad import addBookPayload
from Utilities.configration import config
from Utilities.resources import *
url = config()['API']['endpoint']+ApiResources.addBook
header = {"Content-Type": "application/json"}
response = requests.post(url, json=addBookPayload("pl74"), headers=header,)
print(response.json())
response_json = response.json()
book_ID = response_json['ID']
Error:
Traceback (most recent call last):
File "C:\Users\Muhammad Azmul Haq\PycharmProjects\BackEndProject\APIs\PostAPI.py", line 8, in <module>
url = config()['API']['endpoint']+ApiResources.addBook
File "C:\Users\Muhammad Azmul Haq\AppData\Local\Programs\Python\Python39\lib\configparser.py", line 960, in __getitem__
raise KeyError(key)
KeyError: 'API'
Does anyone have an idea what I did wrong Kind regards?
You are not initializing your global variable in config before accessing it. Try assigning value in the current file,
or
Put all configure in the separate configuration file and import that configuration file.
I am writing a python service with connexion. I have access to the swagger gui of the service via localhost:<port>/ui. However, when I enter localhost:<port> in the browser without the /ui (automatically added by connexion), I get the following message:
{
"detail": "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.",
"status": 404,
"title": "Not Found",
"type": "about:blank"
}
Is it possible to customize this message ? In my case, I want localhost:<port> to return the following message instead:
{"message": "check /ui to have access to the Swagger UI"}
I think I found a solution. Just add the following to the openspec api:
/:
get:
operationId: path.to.function
summary: "my personlized message"
responses:
......
I am using the
telepot.Bot(bot_id).sendAudio(chat_id, file_url)
method, is supposed to send the file, but it returns
Traceback (most recent call last):
File "C:\Users\vinu\AppData\Local\Programs\Python\Python37\lib\site-packages\telepot\__init__.py", line 1158, in collector
callback(item)
File "bot.py", line 72, in handle
bot.sendAudio(chat_id, url)
File "C:\Users\vinu\AppData\Local\Programs\Python\Python37\lib\site-packages\telepot\__init__.py", line 556, in sendAudio
return self._api_request_with_file('sendAudio', _rectify(p), 'audio', audio)
File "C:\Users\vinu\AppData\Local\Programs\Python\Python37\lib\site-packages\telepot\__init__.py", line 496, in _api_request_with_file
return self._api_request(method, _rectify(params), **kwargs)
File "C:\Users\vinu\AppData\Local\Programs\Python\Python37\lib\site-packages\telepot\__init__.py", line 491, in _api_request
return api.request((self._token, method, params, files), **kwargs)
File "C:\Users\vinu\AppData\Local\Programs\Python\Python37\lib\site-packages\telepot\api.py", line 155, in request
return _parse(r)
File "C:\Users\vinu\AppData\Local\Programs\Python\Python37\lib\site-packages\telepot\api.py", line 150, in _parse
raise exception.TelegramError(description, error_code, data)
telepot.exception.TelegramError: ('Bad Request: wrong HTTP URL specified', 400, {'ok': False, 'error_code': 400, 'description': 'Bad Request: wrong HTTP URL specified'})
the same happened with sendPhoto, but I used python requests to send photos
response =requests.post('https://api.telegram.org/bot/sendphoto', files=files`)
I either want to know why the sendAudio() and sendPhoto() methods work or the http url to send audio
with telepot bot.SendPhoto and bot.sendVideo and bot.sendAudio work either with files and urls that contains a file.
In your case it seems that you used and url and it was uncorrect, can you share it?
In my experience it can be because the url contains & instead of &
I have a program that occasionally throws a badStatusLine exception, after catching it we are now getting another error and I can't seem to catch it so the program doesn't stop. Here is what I have, any help would be appreciated.
The error:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "/Users/mattduhon/trading4.py", line 30, in trade
execution.execute_order(event)
File "/Users/mattduhon/execution.py", line 33, in execute_order
params, headers
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1001, in request
self._send_request(method, url, body, headers)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1029, in _send_request
self.putrequest(method, url, **skips)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 892, in putrequest
raise CannotSendRequest()
CannotSendRequest
The file responsible for catching the error:
import httplib
import urllib
from httplib import BadStatusLine
from httplib import CannotSendRequest
class Execution(object):
def __init__(self, domain, access_token, account_id):
self.domain = domain
self.access_token = access_token
self.account_id = account_id
self.conn = self.obtain_connection()
def obtain_connection(self):
return httplib.HTTPSConnection(self.domain)
def execute_order(self, event):
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Bearer " + self.access_token}
params = urllib.urlencode({
"instrument" : event.instrument,
"units" : event.units,
"type" : event.order_type,
"side" : event.side,
"stopLoss" : event.stopLoss,
"takeProfit" : event.takeProfit
})
self.conn.request(
"POST",
"/v1/accounts/%s/orders" % str(self.account_id),
params, headers)
try:
response = self.conn.getresponse().read()
except BadStatusLine as e:
print(e)
except CannotSendRequest as a: ######my attempt at catching the error
print(a)
else:
print response
If you change the final else to:
except:
print "Unexpected error:", sys.exc_info()[0]
raise
You should get the real uncaught error if it's really coming from the try-catch block. But are you sure you haven't gotten into a bad state which excepts outside that block?
In python3:
from urllib.request import Request, urlopen
from urllib.error import URLError, HTTPError
try:
req = Request("wrong url")
except ValueError as e:
if e == "unknown url type: 'wrong url'" :print("bad url")
Why there is no bad url to output in my python console?
Can't compare ValueError message with string
1.Think for you to tell me 'str(e)'
2.It is "unknown url type: 'wrong url'" not "unknown url type: wrong url" ,I have test it in my console.
You should pass it to str first:
if str(e) == "unknown url type: 'wrong url'" :
You are comparing an exception object to a string
You should compare to str(e) to get a match e.g.
from urllib.request import Request, urlopen
from urllib.error import URLError, HTTPError
try:
req = Request("wrong url")
except ValueError as e:
if "unknown url type" in str(e) :
print("bad url")
The line
if "unknown url type" in str(e) :
Accounts for differences in the returned string between python 3.x version.