Pyscript-ModuleNotFoundError:没有名为 'requests' 的模块



我正在用pyscript制作天气网站,但我得到了这个错误ModuleNotFoundError:没有名为'请求'的模块,所以我写了导入请求,我从cmd下载了这个请求模块,但它仍然说ModuleNotFoundError:没有名为'请求'的模块,我如何修复这个错误?

inline code

<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<body>
<py-script src="main.py"></py-script>
<input id="getweather" placeholder="search weather...">
<button id="btngwt" pys-onClick="play_game">sipal</button>
<h1 id="babo"></h1>

</body>
</html>


import requests
import json
search = Element("getweather")
something = Element("babo")
def play_game(*args):
wt = search.value
city = wt #도시 
apiKey = "db1e8e28d93cbbabad4f0162fa37dbdf"
lang = 'kr' #언어
units = 'metric' #화씨 온도를 섭씨 온도로 변경
api = f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={apiKey}&lang={lang}&units={units}"
result = requests.get(api)
result = json.loads(result.text)
something.element.innerText = f"{result}"```

此问题并非Python/PyScript特有。web浏览器沙盒(虚拟机)不提供TCP套接字API。因此,像requests这样的Python包将无法工作。你需要修改你的应用程序来使用支持的浏览器HTTP方法,比如fetch API。

最新更新