python - 如何将 odoo 与 IMDb 集成?
问题描述
我正在尝试将 odoo 与imdb.com集成,它在omdbapi.com上有自己的 API 我需要将电影作为产品在 odoo 上进行购买,然后在网站上说要搜索我应该使用这个 api http://www .omdbapi.com/?apikey= "我必须,但我的钥匙在这里"&t="我要搜索的电影名称"
我试图通过这种方式做到这一点
class Api(http.Controller):
@http.route('/api', auth='public', methods=["get"])
def index(self, **kw):
url = 'http://www.omdbapi.com/?apikey=15439843&t=hello'
r = requests.get(url)
return r.text
它返回一个带有电影 hello 数据的 json 但这里它是一个静态参数我怎样才能使它动态并从字段或数据输入中获取电影名称然后我需要在 product.tempalte 的方法 create 上获取 json 参数
add_product = http.request.env['product.template'].sudo().create({
'name': "movie name form json"
})
return add_product
非常感谢任何帮助
解决方案
我使用 Postman 生成此代码,这将使您了解如何处理来自链接的查询字符串参数
import requests
url = "http://www.omdbapi.com/"
querystring = {"apikey":"15439843","t":"hello"} # your parameters here in query string
headers = { 'Cache-Control': "no-cache", 'Connection': "keep-alive", 'cache-control': "no-cache" }
response = requests.request("GET", url, headers=headers, params=querystring)
print(response.text)
推荐阅读
- excel - 如何设置分页预览?
- r - 在具有 NA 的特定列中进行 mutate 和 ifelse
- java - 不能转换为 java.base/java.util.Optional
- reactjs - React JS:需要拆分正在检索的状态对象
- c# - 如何将 .NET Core 程序的入口点放在它引用的 NuGet 包中
- java - Tomcat 是在收到 post 正文之前还是之后调用 servlet 的 doPost 方法?
- django - 考虑到其他模型字段,如何使用“MinValueValidator”?
- spring - Spring Boot 实体未更新
- aws-api-gateway - 如何在没有明确的招摇定义的情况下在 SAM 中启用“ApiKeyRequired”属性?
- python - 如何在pyqt listwidget中检查项目是否被选中