开发者社区> 问答> 正文

Python当我在 IDLE中执行时是200,但是在Terminal中执行时是404

代码如下:

import requests
file = open("test.txt")
for url in file:
    response = requests.get(url)
    print(response.status_code)

test.txt

https://www.google.com

O/p in Terminal:

404

terminal中的执行

Python 3.6.8 (default, Oct  7 2019, 12:59:55)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> response = requests.get("https://google.com")
>>> response.status_code
200

展开
收起
安忆333 2019-12-02 19:56:11 912 0
1 条回答
写回答
取消 提交回答
  • 文件的末尾会默认加上换行符,可以试下strip

    for url in file:
        response = requests.get(url.strip())
    
    2019-12-02 19:57:31
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载