I have created custom API module for odoo 18. My endpoint REST APIs are working fine in local version. But when I try to use it in the hosted version it gives 404 error.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- 会計
- 在庫
- PoS
- Project
- MRP
この質問にフラグが付けられました
When your custom API module works in your local Odoo instance but gives a 404 error on the hosted version, it indicates that the hosted environment may not be configured to load your custom module or that there are deployment-specific issues. Here are steps to diagnose and resolve this issue:
1. Verify Module Installation on Hosted Version
Ensure your custom API module is installed and available on the hosted instance:
- Check Installed Modules:
- Go to Apps and ensure your module is listed as installed.
- Install/Upgrade Your Module:
- If not installed, install it via the Apps menu or run:
bashCopy codepython3 odoo-bin -u <your_module_name> -c /etc/odoo/odoo.conf
- If not installed, install it via the Apps menu or run:
2. Check the API Endpoint Configuration
- Verify Endpoint Routing: Ensure your custom endpoints are defined correctly in your controllers file and are accessible in the hosted environment.
Example:pythonCopy codefrom odoo import http class MyAPIController(http.Controller): @http.route('/my_api/endpoint', type='json', auth='public', methods=['POST'], csrf=False) def my_api_method(self, **kwargs): return {'message': 'API is working!'}
- Test Endpoint in Hosted Version: Use a tool like curl or Postman to test the endpoint directly:
bashCopy codecurl -X POST https://your-hosted-instance.com/my_api/endpoint -d '{}'
3. Verify Server Logs
- Check Logs for Clues: Look for errors in the Odoo log file (/var/log/odoo/odoo.log or equivalent) when the 404 error occurs.
Key things to look for:- Errors related to module loading.
- Missing or unregistered routes.
bashCopy codegrep '<your_module_name>' /var/log/odoo/odoo.log
4. Inspect Hosted Environment Configuration
- Custom Module Deployment: Ensure the custom module is properly uploaded to the hosted instance. Verify:
- The module is in the addons directory or an equivalent path.
- The path to your custom module is listed in the addons_path of the Odoo configuration file.
iniCopy codeaddons_path = /usr/lib/python3/dist-packages/odoo/addons,/opt/odoo/custom_addons
- Restart Odoo Server: If you recently added or updated the module, ensure the server is restarted:
bashCopy codesudo service odoo restart
5. Verify Access Control and Authentication
- Authentication Requirements: If your API requires authentication, ensure the credentials used in the hosted version are correct.
- If using auth='public', ensure the endpoint doesn't have unnecessary restrictions.
- For authenticated endpoints, verify the Authorization header is included in requests.
- Cross-Origin Resource Sharing (CORS): If accessing the API from a different domain, ensure the hosted instance has proper CORS settings.
6. Firewall or Proxy Issues
- Firewall Rules: Ensure that the hosted environment allows traffic on the required port (usually 8069 for Odoo).
- Reverse Proxy Configuration: If using a reverse proxy (e.g., Nginx), ensure it forwards requests to your custom API correctly. Update the proxy configuration if necessary.
Example Nginx configuration for API:nginxCopy codelocation /my_api/ { proxy_pass http://127.0.0.1:8069/my_api/; }
7. Debugging in Hosted Environment
- Enable Debug Mode: Temporarily enable debug mode to inspect if your module routes are loaded:
bashCopy codepython3 odoo-bin -c /etc/odoo/odoo.conf --dev=all
- Test All Routes: Use Odoo's route debugging to check if your custom route is registered:
- Access /web/environment/routes to see all loaded routes.
8. Redeploy the Module
If the issue persists, re-upload and reinstall your module:
- Remove the existing module from the addons path.
- Re-upload the module folder to the appropriate addons_path.
- Restart the Odoo server and reinstall the module.
9. Host Provider Limitations
If your Odoo instance is on a hosted SaaS platform (e.g., Odoo Online), it may restrict custom module usage or require specific deployment steps. Contact your hosting provider to confirm:
- If custom modules are supported.
- The process to deploy custom modules in their environment.
Summary Checklist
- Ensure your module is installed and accessible in the hosted instance.
- Verify the API endpoint configuration in your module.
- Check server logs for routing or deployment errors.
- Confirm the module is in the addons_path.
- Restart the Odoo server after module changes.
- Ensure the hosted instance allows traffic to your API endpoint.
- Confirm with the hosting provider for any restrictions on custom modules.
関連投稿 | 返信 | ビュー | 活動 | |
---|---|---|---|---|
|
1
3月 25
|
943 | ||
|
1
8月 25
|
346 | ||
|
2
7月 25
|
2794 | ||
|
3
7月 25
|
608 | ||
|
4
7月 25
|
367 |