<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Python Help - Downloading Images from URL in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/python-help-downloading-images-from-url/m-p/1533341#M87827</link>
    <description>&lt;P&gt;I'm pretty new to python but I'm using the following script to download images from links that live in the attribute table of my layer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import urllib.request
import os

# Set the workspace
arcpy.env.workspace = r"C:\workspace\GIS.gdb"

# Define the feature class and the fields
fc = r"C:\layer_zip.shp"
fields = ["image_url", "id"]

# Define the output directory
output_dir = r"C:\Users\download"

# Loop through each row in the feature class
with arcpy.da.SearchCursor(fc, fields) as cursor:
    for row in cursor:
        photo_url = row[0]
        object_id = row[1]
        
        # Construct the file name using the OBJECTID or another unique identifier
        photo_filename = os.path.join(output_dir, f"{object_id}.jpg")
        
        # Download the image from the URL and save it to the output directory
        urllib.request.urlretrieve(photo_url, photo_filename)

print("Photos have been downloaded and saved.")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It will download several photos before I get this error message&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;URLError&lt;/SPAN&gt;                                  Traceback (most recent call last)
In  &lt;SPAN class=""&gt;[35]&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;25&lt;/SPAN&gt;:    urllib.request.urlretrieve(photo_url, photo_filename)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\urllib\request.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;urlretrieve&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;241&lt;/SPAN&gt;:   &lt;SPAN class=""&gt;with&lt;/SPAN&gt; contextlib.closing(urlopen(url, data)) &lt;SPAN class=""&gt;as&lt;/SPAN&gt; fp:

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\urllib\request.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;urlopen&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;216&lt;/SPAN&gt;:   &lt;SPAN class=""&gt;return&lt;/SPAN&gt; opener.open(url, data, timeout)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\urllib\request.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;open&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;519&lt;/SPAN&gt;:   response = &lt;SPAN class=""&gt;self&lt;/SPAN&gt;._open(req, data)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\urllib\request.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;_open&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;536&lt;/SPAN&gt;:   result = &lt;SPAN class=""&gt;self&lt;/SPAN&gt;._call_chain(&lt;SPAN class=""&gt;self&lt;/SPAN&gt;.handle_open, protocol, protocol +

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\urllib\request.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;_call_chain&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;496&lt;/SPAN&gt;:   result = func(*args)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\urllib\request.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;https_open&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;1391&lt;/SPAN&gt;:  &lt;SPAN class=""&gt;return&lt;/SPAN&gt; &lt;SPAN class=""&gt;self&lt;/SPAN&gt;.do_open(http.client.HTTPSConnection, req,

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\urllib\request.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;do_open&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;1351&lt;/SPAN&gt;:  &lt;SPAN class=""&gt;raise&lt;/SPAN&gt; URLError(err)

&lt;SPAN class=""&gt;URLError&lt;/SPAN&gt;: &amp;lt;urlopen error [Errno 11002] getaddrinfo failed&amp;gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Any help is appreciated!&lt;/P&gt;</description>
    <pubDate>Fri, 30 Aug 2024 14:02:45 GMT</pubDate>
    <dc:creator>aprhyde11</dc:creator>
    <dc:date>2024-08-30T14:02:45Z</dc:date>
    <item>
      <title>Python Help - Downloading Images from URL</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-help-downloading-images-from-url/m-p/1533341#M87827</link>
      <description>&lt;P&gt;I'm pretty new to python but I'm using the following script to download images from links that live in the attribute table of my layer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import urllib.request
import os

# Set the workspace
arcpy.env.workspace = r"C:\workspace\GIS.gdb"

# Define the feature class and the fields
fc = r"C:\layer_zip.shp"
fields = ["image_url", "id"]

# Define the output directory
output_dir = r"C:\Users\download"

# Loop through each row in the feature class
with arcpy.da.SearchCursor(fc, fields) as cursor:
    for row in cursor:
        photo_url = row[0]
        object_id = row[1]
        
        # Construct the file name using the OBJECTID or another unique identifier
        photo_filename = os.path.join(output_dir, f"{object_id}.jpg")
        
        # Download the image from the URL and save it to the output directory
        urllib.request.urlretrieve(photo_url, photo_filename)

print("Photos have been downloaded and saved.")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It will download several photos before I get this error message&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;URLError&lt;/SPAN&gt;                                  Traceback (most recent call last)
In  &lt;SPAN class=""&gt;[35]&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;25&lt;/SPAN&gt;:    urllib.request.urlretrieve(photo_url, photo_filename)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\urllib\request.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;urlretrieve&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;241&lt;/SPAN&gt;:   &lt;SPAN class=""&gt;with&lt;/SPAN&gt; contextlib.closing(urlopen(url, data)) &lt;SPAN class=""&gt;as&lt;/SPAN&gt; fp:

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\urllib\request.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;urlopen&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;216&lt;/SPAN&gt;:   &lt;SPAN class=""&gt;return&lt;/SPAN&gt; opener.open(url, data, timeout)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\urllib\request.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;open&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;519&lt;/SPAN&gt;:   response = &lt;SPAN class=""&gt;self&lt;/SPAN&gt;._open(req, data)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\urllib\request.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;_open&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;536&lt;/SPAN&gt;:   result = &lt;SPAN class=""&gt;self&lt;/SPAN&gt;._call_chain(&lt;SPAN class=""&gt;self&lt;/SPAN&gt;.handle_open, protocol, protocol +

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\urllib\request.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;_call_chain&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;496&lt;/SPAN&gt;:   result = func(*args)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\urllib\request.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;https_open&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;1391&lt;/SPAN&gt;:  &lt;SPAN class=""&gt;return&lt;/SPAN&gt; &lt;SPAN class=""&gt;self&lt;/SPAN&gt;.do_open(http.client.HTTPSConnection, req,

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\urllib\request.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;do_open&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;1351&lt;/SPAN&gt;:  &lt;SPAN class=""&gt;raise&lt;/SPAN&gt; URLError(err)

&lt;SPAN class=""&gt;URLError&lt;/SPAN&gt;: &amp;lt;urlopen error [Errno 11002] getaddrinfo failed&amp;gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Any help is appreciated!&lt;/P&gt;</description>
      <pubDate>Fri, 30 Aug 2024 14:02:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-help-downloading-images-from-url/m-p/1533341#M87827</guid>
      <dc:creator>aprhyde11</dc:creator>
      <dc:date>2024-08-30T14:02:45Z</dc:date>
    </item>
    <item>
      <title>Re: Python Help - Downloading Images from URL</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-help-downloading-images-from-url/m-p/1533405#M87831</link>
      <description>&lt;P&gt;I would suggest running the urllib.request in a try statement, that way the script doesn't hang on a single picture, and you can see if it is just one url or all of them that are problematic:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Download the image from the URL and save it to the output directory
try:
     urllib.request.urlretrieve(photo_url, photo_filename)
except URLError:
     print(photo_url)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;2.14.0.0&lt;/DIV&gt;</description>
      <pubDate>Fri, 30 Aug 2024 15:23:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-help-downloading-images-from-url/m-p/1533405#M87831</guid>
      <dc:creator>Ben_Ba</dc:creator>
      <dc:date>2024-08-30T15:23:36Z</dc:date>
    </item>
  </channel>
</rss>

