gpt4 book ai didi

Python 导入错误 : No module name parse

转载 作者:行者123 更新时间:2023-12-03 09:09:20 26 4
gpt4 key购买 nike

我不断收到同样的错误,我已经尝试了所有我知道如何解决它的方法。我得到的错误是:ImportError: No module name parse有谁知道如何解决这一问题?我目前正在运行 python 2.7.12。这也是我的代码:

 # -*- coding: utf-8 -*-

import http.client, urllib.parse, json


# **********************************************
# *** Update or verify the following values. ***
# **********************************************

# Replace the subscriptionKey string value with your valid subscription key.
subscriptionKey = "My_Access_Key"

# Verify the endpoint URI. At this writing, only one endpoint is used for Bing
# search APIs. In the future, regional endpoints may be available. If you
# encounter unexpected authorization errors, double-check this value against
# the endpoint for your Bing Web search instance in your Azure dashboard.
host = "api.cognitive.microsoft.com"
path = "/bing/v7.0/search"

term = "Microsoft Cognitive Services"

def BingWebSearch(search):
"Performs a Bing Web search and returns the results."

headers = {'Ocp-Apim-Subscription-Key': subscriptionKey}
conn = http.client.HTTPSConnection(host)
query = urllib.parse.quote(search)
conn.request("GET", path + "?q=" + query, headers=headers)
response = conn.getresponse()
headers = [k + ": " + v for (k, v) in response.getheaders()
if k.startswith("BingAPIs-") or k.startswith("X-MSEdge-")]
return headers, response.read().decode("utf8")

if len(subscriptionKey) == 32:

print('Searching the Web for: ', term)

headers, result = BingWebSearch(term)
print("\nRelevant HTTP Headers:\n")
print("\n".join(headers))
print("\nJSON Response:\n")
print(json.dumps(json.loads(result), indent=4))

else:

print("Invalid Bing Search API subscription key!")
print("Please paste yours into the source code.")

最佳答案

点赞snakecharmerb告诉你,urllib.parse 来自 Python3。

我认为你应该使用 urlparse作为 urllib.parsehttplib作为 http模块。

如果你已经在你的机器上安装了 Python3(来自 apt 或类似的)也许它不会改变你的 /usr/bin/python链接到较新的版本,但我很确定你应该有一个 python3python3.x命令安装。

如果你想替换 python带有 python3.x 的命令您必须创建一个指向您的符号链接(symbolic link) /usr/bin文件夹。你可以这样做:
sudo rm /usr/bin/python
sudo ln -s <path_to_your_python3_bin> /usr/bin/python

也许 rm 不是必需的,但它没有伤害。

关于Python 导入错误 : No module name parse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48585899/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com