在 GitLab-Runner 對(duì)我的博客數(shù)據(jù)進(jìn)行預(yù)處理時(shí)蒸辆,requests 這個(gè)模塊會(huì)首先嘗試通過(guò) IPv6 進(jìn)行訪問(wèn)跟磨,由于一些未知的原因定罢,會(huì)一直超時(shí)重試糠溜,而不會(huì)轉(zhuǎn)到 IPv4 再次獲取資源淳玩,所以導(dǎo)致 CI/CD 一直失敗。
迫不得已只能讓 requests 強(qiáng)制使用 IPv4 來(lái)獲取資源非竿。
import socket
import requests.packages.urllib3.util.connection as urllib3_cn
def allowed_gai_family():
"""
https://github.com/shazow/urllib3/blob/master/urllib3/util/connection.py
"""
family = socket.AF_INET
return family
urllib3_cn.allowed_gai_family = allowed_gai_family
如果要強(qiáng)制使用 IPv6蜕着,那么就是
def allowed_gai_family():
family = socket.AF_INET
if urllib3_cn.HAS_IPV6:
family = socket.AF_INET6 # force ipv6 only if it is available
return family