【问题标题】:httplib2 :- argument should be integer or bytes-like object, not 'str'httplib2 :- 参数应该是整数或类似字节的对象,而不是 'str'
【发布时间】:2021-01-26 10:38:34
【问题描述】:

我正在使用 Google Indexing API,但出现此错误

参数应该是整数或类似字节的对象,而不是'str'

当我在本地机器上运行它时,我正在 Django 服务器上实现 API,它运行得很好。 但是当我把它放在 pythonanywhere 上时,它给了我上述错误。我不知道这个错误的原因是什么。 这是函数

def demo(request):
    context = {}
    if request.GET:
        link = request.GET.get('link')
        key = request.GET.get('key')

        if link and key:
            context = {
                'link': link,
                'key': key,
            }
            
            try:
                key = json.loads(key)
            except:
                return render(request, 'google_api_demo/index.html', context)
            scope = [ "https://www.googleapis.com/auth/indexing" ]
            endpoint = "https://indexing.googleapis.com/v3/urlNotifications:publish"

            credentials = ServiceAccountCredentials.from_json_keyfile_dict(key, scopes=scope)
            http = credentials.authorize(httplib2.Http())
            content = bytes(str({
              "url": f"{link}",
              "type": "URL_UPDATED",
            }), encoding='utf-8')
            response, content = http.request(endpoint, method="POST", body=content)
            context['response'] = response
            context['content'] = content
            return render(request, 'google_api_demo/index.html', context)

    return render(request, 'google_api_demo/index.html', context)

【问题讨论】:

    标签: python django linux httplib2


    【解决方案1】:

    other cases 中,PySocks 引发了异常,升级PySocks 解决了它。假设您使用python3.8 在虚拟环境之外运行它,使用pip3.8 install --user --force-reinstall PySocks 升级PySocs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 2020-09-25
      • 2017-02-15
      • 1970-01-01
      • 2021-06-29
      相关资源
      最近更新 更多