Python 无法使用Try访问查询的第三个URL,除非

Python 无法使用Try访问查询的第三个URL,除非,python,Python,它不会转到第三个url- try: "code here..." except requests.exceptions.ConnectionError: pass # doesn't pass to try: 这是密码- import requests try: for url in ['google.com', 'skypeassets.com', 'yahoo.com']: http = ("http://") url2

它不会转到第三个url-

try:
        "code here..."
except requests.exceptions.ConnectionError:
    pass  # doesn't pass to try:
这是密码-

import requests

try:
    for url in ['google.com', 'skypeassets.com', 'yahoo.com']:

        http = ("http://")
        url2 = (http + url)
        page = requests.get(url2)

        if page.status_code == 200:
            print('Success!')
        elif page.status_code == 404:
            print('Not Found.')

except requests.exceptions.ConnectionError:
    print("This site cannot be reached")
        pass
输出-

成功
无法访问此网站

(对于第三个url-应该说-Success!,但是跳过)
除了之外的
一次只能在其主体或块内捕获一个异常。
这意味着您必须在
for
循环中使用它

import requests

for url in ['google.com', 'skypeassets.com', 'yahoo.com']:
    try:
        http = "http://"
        url2 = http + url
        page = requests.get(url2)

        if page.status_code == 200:
            print('Success!')
        elif page.status_code == 404:
            print('Not Found.')

    except requests.exceptions.ConnectionError:
        print("This site cannot be reached")
你的尝试应该在循环中。