<?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 Re: RuntimeError: Value type is incompatible with the field type in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/runtimeerror-value-type-is-incompatible-with-the/m-p/1525000#M71291</link>
    <description>&lt;P&gt;Hey &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/807216"&gt;@DanielleKuchler&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For testing purposes, you may want to attempt to plug this right before your for loop. This will print out a small report of what each date time is, you may also want to check to see if it is a certain index where this happens. If even one of the date_time variables are incorrect, it will stop the execution when it is reached.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for i in data:
        date_time = water_data["value"]["timeSeries"][0]["values"][0]["value"][0]["dateTime"]
        print(f"Date Time of {date_time} is of type {type(date_time)}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;You may also try manually inputting a row using the edit cursor, with different types of date time format, here is a link to many date/time formats: &lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/mapping/time/supported-field-formats.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/help/mapping/time/supported-field-formats.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Cody&lt;/P&gt;</description>
    <pubDate>Wed, 21 Aug 2024 11:18:44 GMT</pubDate>
    <dc:creator>CodyPatterson</dc:creator>
    <dc:date>2024-08-21T11:18:44Z</dc:date>
    <item>
      <title>RuntimeError: Value type is incompatible with the field type</title>
      <link>https://community.esri.com/t5/python-questions/runtimeerror-value-type-is-incompatible-with-the/m-p/1524834#M71287</link>
      <description>&lt;P&gt;Hi all. I am very new to using Python Notebooks in ArcGIS Pro. I am trying to fill one row of a table in ArcGIS Pro with data that I extracted from the USGS website (using their Web Service URL Generation tool). I have been able to request the data from the url, but am running into issues when it comes to adding it into the table within my geodatabase. The current field type I have for the field "date_time" is "DATE", so I am not sure what is going wrong.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The error I get after running the last line of code is:&amp;nbsp;&lt;/STRONG&gt;&lt;EM&gt;"RuntimeError: The value type is incompatible with the field type [date_time]."&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;Any advice or suggestions would be appreciated!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#create a new table
#set arcpy workspace to your geodatabase
arcpy.env.workspace="C:\\My GIS Projects\\Lake Levels USGS\\Lake Levels USGS.gdb"

#set variable outpath
outpath=arcpy.env.workspace

#create new, empty table
arcpy.CreateTable_management(outpath, "Riffe_Lake_Level")

#create fields in empty table
arcpy.AddField_management("Riffe_Lake_Level", "site_name", "STRING")
arcpy.AddField_management("Riffe_Lake_Level", "date_time", "DATE")
arcpy.AddField_management("Riffe_Lake_Level", "station_id", "LONG")
arcpy.AddField_management("Riffe_Lake_Level", "agency_code", "STRING")
arcpy.AddField_management("Riffe_Lake_Level", "waterelev", "DOUBLE")

#use first table as a template for a second table
arcpy.CreateTable_management(outpath, "Alder_Lake_Level", "Riffe_Lake_Level")

#edit table to allow editing of field values
editrows = arcpy.da.InsertCursor("Riffe_Lake_Level", ["site_name", "date_time", "station_id", "agency_code", "waterelev"])
editrows.fields

#import USGS water elevation data
import urllib.parse
import urllib.request
import json
import requests

usgs_water_api = "https://waterservices.usgs.gov/nwis/dv/?format=json&amp;amp;sites=14234800&amp;amp;siteStatus=all"
api_response = requests.get(usgs_water_api)

water_data = api_response.json()

#define values for fields
for i in data:
        site_name = water_data["value"]["timeSeries"][0]["sourceInfo"]["siteName"]
        date_time = water_data["value"]["timeSeries"][0]["values"][0]["value"][0]["dateTime"]
        station_id = water_data["value"]["timeSeries"][0]["sourceInfo"]["siteCode"][0]["value"]
        agency_code = water_data["value"]["timeSeries"][0]["sourceInfo"]["siteCode"][0]["agencyCode"]
        waterelev = water_data["value"]["timeSeries"][0]["values"][0]["value"][0]["value"]
        row = [site_name, date_time, station_id, agency_code, waterelev]
        print(row)
#populate row in data table
        editrows.insertRow(row)
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2024 23:54:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtimeerror-value-type-is-incompatible-with-the/m-p/1524834#M71287</guid>
      <dc:creator>DanielleKuchler</dc:creator>
      <dc:date>2024-08-20T23:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: RuntimeError: Value type is incompatible with the field type</title>
      <link>https://community.esri.com/t5/python-questions/runtimeerror-value-type-is-incompatible-with-the/m-p/1524839#M71288</link>
      <description>&lt;P&gt;check the source types, a date may look like one, but it could be string/text&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2024 00:07:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtimeerror-value-type-is-incompatible-with-the/m-p/1524839#M71288</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-08-21T00:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: RuntimeError: Value type is incompatible with the field type</title>
      <link>https://community.esri.com/t5/python-questions/runtimeerror-value-type-is-incompatible-with-the/m-p/1525000#M71291</link>
      <description>&lt;P&gt;Hey &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/807216"&gt;@DanielleKuchler&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For testing purposes, you may want to attempt to plug this right before your for loop. This will print out a small report of what each date time is, you may also want to check to see if it is a certain index where this happens. If even one of the date_time variables are incorrect, it will stop the execution when it is reached.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for i in data:
        date_time = water_data["value"]["timeSeries"][0]["values"][0]["value"][0]["dateTime"]
        print(f"Date Time of {date_time} is of type {type(date_time)}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;You may also try manually inputting a row using the edit cursor, with different types of date time format, here is a link to many date/time formats: &lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/mapping/time/supported-field-formats.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/help/mapping/time/supported-field-formats.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Cody&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2024 11:18:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtimeerror-value-type-is-incompatible-with-the/m-p/1525000#M71291</guid>
      <dc:creator>CodyPatterson</dc:creator>
      <dc:date>2024-08-21T11:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: RuntimeError: Value type is incompatible with the field type</title>
      <link>https://community.esri.com/t5/python-questions/runtimeerror-value-type-is-incompatible-with-the/m-p/1525041#M71294</link>
      <description>&lt;P&gt;If it is the datetime field causing the issue, then share an example or two of the datetimes from the web service and save community members the effort of having to go retrieve it themselves to help you.&lt;/P&gt;&lt;P&gt;Retrieving the JSON, it looks like the web service is returning datetime as a string in the following format:&amp;nbsp; "2024-08-21T13:08:33.583Z".&amp;nbsp; That looks to be an ISO8601 compliant time format string, but currently the Data Access cursors cannot parse it (I have logged a defect already).&amp;nbsp; So, you are going to have to manipulate the time string into a simpler format that can be parsed.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2024 13:21:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtimeerror-value-type-is-incompatible-with-the/m-p/1525041#M71294</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2024-08-21T13:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: RuntimeError: Value type is incompatible with the field type</title>
      <link>https://community.esri.com/t5/python-questions/runtimeerror-value-type-is-incompatible-with-the/m-p/1527535#M71309</link>
      <description>&lt;P&gt;I'm not sure what this loop is for, you haven't defined `&lt;FONT face="courier new,courier"&gt;data&lt;/FONT&gt;` anywhere, the `&lt;FONT face="courier new,courier"&gt;water_data&lt;/FONT&gt;` variable is a dict not a list/tuple and you don't use the `&lt;FONT face="courier new,courier"&gt;i&lt;/FONT&gt;` inside the loop.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#define values for fields
for i in data:&lt;/LI-CODE&gt;&lt;P&gt;Try converting the `&lt;FONT face="courier new,courier"&gt;date_time&lt;/FONT&gt;` string to a `&lt;FONT face="courier new,courier"&gt;datetime&lt;/FONT&gt;` object.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests
from datetime import datetime
usgs_water_api = "https://waterservices.usgs.gov/nwis/dv/?format=json&amp;amp;sites=14234800&amp;amp;siteStatus=all"
api_response = requests.get(usgs_water_api)
water_data = api_response.json()

date_time = water_data["value"]["timeSeries"][0]["values"][0]["value"][0]["dateTime"]
date_time = datetime.fromisoformat(date_time)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2024 23:04:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtimeerror-value-type-is-incompatible-with-the/m-p/1527535#M71309</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2024-08-26T23:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: RuntimeError: Value type is incompatible with the field type</title>
      <link>https://community.esri.com/t5/python-questions/runtimeerror-value-type-is-incompatible-with-the/m-p/1529639#M71355</link>
      <description>&lt;P&gt;Switching source type to field worked! I'm glad it wasn't a more complicated issue. Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2024 18:36:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtimeerror-value-type-is-incompatible-with-the/m-p/1529639#M71355</guid>
      <dc:creator>DanielleKuchler</dc:creator>
      <dc:date>2024-08-29T18:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: RuntimeError: Value type is incompatible with the field type</title>
      <link>https://community.esri.com/t5/python-questions/runtimeerror-value-type-is-incompatible-with-the/m-p/1529650#M71356</link>
      <description>&lt;P&gt;Thank you for the insight and for taking the time to retrieve the source data! Apologies for not putting those examples here. Changing the field type to string allowed the data to be retrieved for the time being.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2024 18:40:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtimeerror-value-type-is-incompatible-with-the/m-p/1529650#M71356</guid>
      <dc:creator>DanielleKuchler</dc:creator>
      <dc:date>2024-08-29T18:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: RuntimeError: Value type is incompatible with the field type</title>
      <link>https://community.esri.com/t5/python-questions/runtimeerror-value-type-is-incompatible-with-the/m-p/1529700#M71359</link>
      <description>&lt;P&gt;Thank you for your help with the "for loop" comment, you're right, I didn't actually need that as part of my code for this scenario.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2024 19:21:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtimeerror-value-type-is-incompatible-with-the/m-p/1529700#M71359</guid>
      <dc:creator>DanielleKuchler</dc:creator>
      <dc:date>2024-08-29T19:21:18Z</dc:date>
    </item>
    <item>
      <title>Re: RuntimeError: Value type is incompatible with the field type</title>
      <link>https://community.esri.com/t5/python-questions/runtimeerror-value-type-is-incompatible-with-the/m-p/1529701#M71360</link>
      <description>&lt;P&gt;For anyone curious, this is what ended up working:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;#create a new table
#set arcpy workspace to your geodatabase
arcpy.env.workspace="C:\\My GIS Projects\\Lake Levels USGS\\Lake Levels USGS.gdb"

#set variable outpath
outpath=arcpy.env.workspace

# Define the name of the new table
table_name = 'RiffeLakeElev'

#create new, empty table
arcpy.CreateTable_management(outpath, "Riffe_Lake_Level")

#create fields in empty table
arcpy.AddField_management("Riffe_Lake_Level", "site_name", "STRING")
arcpy.AddField_management("Riffe_Lake_Level", "date_time", "STRING")
arcpy.AddField_management("Riffe_Lake_Level", "station_id", "STRING")
arcpy.AddField_management("Riffe_Lake_Level", "agency_code", "STRING")
arcpy.AddField_management("Riffe_Lake_Level", "waterelev", "DOUBLE")

#edit table to allow editing of field values
editrows = arcpy.da.InsertCursor("Riffe_Lake_Level", ["site_name", "date_time", "station_id", "agency_code", "waterelev"])
editrows.fields

#import USGS water elevation data
import urllib.parse
import urllib.request
import json
import requests

usgs_water_api = "https://waterservices.usgs.gov/nwis/dv/?format=json&amp;amp;sites=14234800&amp;amp;siteStatus=all"
api_response = requests.get(usgs_water_api, verify=False)

water_data = api_response.json()  

#define values for fields

site_name = water_data["value"]["timeSeries"][0]["sourceInfo"]["siteName"]
date_time = water_data["value"]["timeSeries"][0]["values"][0]["value"][0]["dateTime"]
station_id = water_data["value"]["timeSeries"][0]["sourceInfo"]["siteCode"][0]["value"]
agency_code = water_data["value"]["timeSeries"][0]["sourceInfo"]["siteCode"][0]["agencyCode"]
waterelev = water_data["value"]["timeSeries"][0]["values"][0]["value"][0]["value"]

row = [site_name, date_time, station_id, agency_code, waterelev]
print(row)

#populate row in data table
editrows.insertRow(row)

#finish editing
del editrows&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 29 Aug 2024 19:23:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtimeerror-value-type-is-incompatible-with-the/m-p/1529701#M71360</guid>
      <dc:creator>DanielleKuchler</dc:creator>
      <dc:date>2024-08-29T19:23:41Z</dc:date>
    </item>
  </channel>
</rss>

