Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python httplib2:-参数应该是整数或类似对象的字节,而不是';str';_Python_Django_Linux_Httplib2 - Fatal编程技术网

Python httplib2:-参数应该是整数或类似对象的字节,而不是';str';

Python httplib2:-参数应该是整数或类似对象的字节,而不是';str';,python,django,linux,httplib2,Python,Django,Linux,Httplib2,我正在使用谷歌索引API,我得到了这个错误 参数应为整数或类似字节的对象,而不是“str” 我在Django服务器上实现API,当我在本地机器上运行它时,它运行得很好。 但是当我把它放在pythonany上,它给了我上面的错误。我不知道这个错误的原因是什么。 下面是函数 def demo(request): context = {} if request.GET: link = request.GET.get('link') key = reque

我正在使用谷歌索引API,我得到了这个错误

参数应为整数或类似字节的对象,而不是“str”

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

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)

在这个例子中,异常是由
PySocks
引发的,升级
PySocks
解决了这个问题。假设您使用
python3.8
在虚拟环境之外运行它,并使用
pip3.8安装--user--force重新安装PySocks
升级PySocks,则异常是由
PySocks
引发的,升级
PySocks
解决了它。假设您使用
python3.8
在虚拟环境之外运行它,则使用
pip3.8安装--user--force重新安装PySocks升级PySocs

谢谢,它成功了谢谢