【问题标题】:how to integrate odoo with IMDb?如何将 odoo 与 IMDb 集成?
【发布时间】:2020-05-14 12:25:38
【问题描述】:

我正在尝试将 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

非常感谢任何帮助

【问题讨论】:

    标签: python api web-services integration odoo


    【解决方案1】:

    我使用 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-18
      • 2014-08-30
      相关资源
      最近更新 更多