-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Closed
Labels
code-executionexecute generated codeexecute generated codegood first issueGood for newcomersGood for newcomers
Description
请尝试使用以下更新的代码:
```py
# filename: news_report.py
import requests
url = 'https://newsapi.org/v2/top-headlines?country=us&apiKey=<your_api_key>'
response = requests.get(url)
data = response.json()
headlines = [article['title'] for article in data['articles']]
markdown_report = '\n'.join(['- ' + headline for headline in headlines])
print(markdown_report)
在您的计算机上创建一个名为news_report.py
的新文件,并将此代码粘贴到其中。 然后,请替换<your_api_key>
为您的News API密钥。 如果您没有密钥,请访问News API注册并获取一个免费的API密钥。
保存文件后,在命令行中运行以下命令以执行脚本:
python news_report.py
当脚本成功执行时,它将显示新闻标题列表。 请注意,由于API限制和网络延迟,结果可能有所不同。
EXECUTING CODE BLOCK 0 (inferred language is py)...
user_proxy (to assistant):
exitcode: 1 (execution failed)
Code output:
unknown language py
How to handle py code?
Obviously, py is a valid lan in most markdown format...... and very human knows it's python, why this stupid agent not?
Metadata
Metadata
Assignees
Labels
code-executionexecute generated codeexecute generated codegood first issueGood for newcomersGood for newcomers