@@ -88,9 +88,6 @@ def process_image_data(image_data, mime_type, url):
88
88
89
89
def http_to_pil_image (url ):
90
90
"""http_to_pil_image"""
91
- if is_public_url (url ) and int (os .getenv ("DOWNLOAD_WITH_TP_SERVER" , "0" )):
92
- return http_to_pil_image_with_tp_server (url )
93
-
94
91
response = requests .get (url )
95
92
if response .status_code != 200 :
96
93
raise Exception ("Failed to download the image from URL." )
@@ -106,60 +103,6 @@ def http_to_pil_image(url):
106
103
return pil_image
107
104
108
105
109
- def http_to_pil_image_with_tp_server (url , retry_time = 6 ):
110
- """cnap平台没有外网访问权限,需要使用tp服务下载图片"""
111
- proxies = [
112
- {"http" : "http://10.229.197.142:8807" },
113
- {"http" : "http://10.229.197.161:8804" },
114
- {"http" : "http://10.229.198.143:8804" },
115
- {"http" : "http://10.122.108.164:8807" },
116
- {"http" : "http://10.122.108.165:8807" },
117
- {"http" : "http://10.122.108.166:8807" },
118
- {"http" : "http://10.122.108.168:8801" },
119
- {"http" : "http://10.122.150.146:8802" },
120
- {"http" : "http://10.122.150.158:8802" },
121
- {"http" : "http://10.122.150.164:8801" },
122
- {"http" : "http://10.143.51.38:8813" },
123
- {"http" : "http://10.143.103.42:8810" },
124
- {"http" : "http://10.143.194.45:8804" },
125
- {"http" : "http://10.143.226.25:8801" },
126
- {"http" : "http://10.143.236.12:8807" },
127
- {"http" : "http://10.143.238.36:8807" },
128
- {"http" : "http://10.144.71.30:8807" },
129
- {"http" : "http://10.144.73.16:8804" },
130
- {"http" : "http://10.144.138.36:8801" },
131
- {"http" : "http://10.144.152.40:8810" },
132
- {"http" : "http://10.144.199.29:8810" },
133
- {"http" : "http://10.144.251.29:8813" },
134
- ]
135
- headers = {
136
- "X-Tp-Authorization" : "Basic RVJOSUVMaXRlVjpFUk5JRUxpdGVWXzFxYXo0cmZ2M2VkYzV0Z2Iyd3N4LWJmZS10cA==" ,
137
- "scheme" : "https" ,
138
- }
139
-
140
- new_url = url .replace ("https://" , "http://" ) if url .startswith ("https://" ) else url
141
-
142
- # 代理可能不稳定,需要重试
143
- for idx in range (retry_time ):
144
- try :
145
- response = requests .get (new_url , headers = headers , proxies = random .choice (proxies ))
146
- if response .status_code == 200 :
147
- image_data = io .BytesIO (response .content )
148
-
149
- mime_type = response .headers .get ("Content-Type" )
150
- if mime_type is None :
151
- mime_type , _ = mimetypes .guess_type (url )
152
-
153
- data_processor_logger .info (f"Detected MIME type: { mime_type } " ) # 调试信息
154
- pil_image = process_image_data (image_data , mime_type , url )
155
-
156
- return pil_image
157
- except Exception as e :
158
- data_processor_logger .error (f"Failed to download the image, idx: { idx } , URL: { url } , error: { e } " )
159
-
160
- raise Exception (f"Failed to download the image from URL: { url } " )
161
-
162
-
163
106
def base64_to_pil_image (base64_string ):
164
107
"""base64_to_pil_image"""
165
108
image_bytes = base64 .b64decode (base64_string )
0 commit comments