You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用ArcGIS Python API上传图片报Item type not valid错误,求合法类型列表

问题描述

我尝试使用以下基于ArcGIS Python API的代码上传图片:

def handle_attachments_api(
    portal_domain: str,
    portal_username: str,
    portal_password: str,
    data_type: str = None,
    data_url: str = None,
    filename: str = None,
    type_keywords: str = None,
    description: str = None,
    title: str = None,
    url: str = None,
    text: str = None,
    tags: str = None,
    snippet: str = None,
    extent: str = None,
    spatial_reference: str = None,
    access_information: str = None,
    license_info: str = None,
    culture: str = None,
    comments_enabled: bool = True,
    access: str = None,
    overwrite: bool = False,
    data: str = None,
    thumbnail: str = None,
    metadata: str = None,
    owner: str = None,
    folder: str = None,
    item_id: guid = None,
):
    gis = GIS(
        url=f"https://{portal_domain}/portal",
        username=portal_username,
        password=portal_password
    )

    item_properties = {
        "type": data_type,
        "dataUrl": data_url,
        "filename": filename,
        "typeKeywords": type_keywords,
        "description": description,
        "title": title,
        "url": url,
        "text": text,
        "tags": tags,
        "snippet": snippet,
        "extent": extent,
        "spatialReference": spatial_reference,
        "accessInformation": access_information,
        "licenseInfo": license_info,
        "culture": culture,
        "commentsEnabled": comments_enabled,
        "access": access,
        "overwrite": overwrite,
    }

    gis.content.add(
        item_properties=item_properties,
        data=data,
        thumbnail=thumbnail,
        metadata=metadata,
        owner=owner,
        folder=folder,
        item_id=item_id
    )

但当我将item类型设为'jpg'时,出现如下错误:

>..\..\..\..\..\AppData\Local\ESRI\conda\envs\arcgispro-py3-ps\lib\site-packages\arcgis\gis\__init__.py:6837: in add
>    itemid = self._portal.add_item(
>..\..\..\..\..\AppData\Local\ESRI\conda\envs\arcgispro-py3-ps\lib\site-packages\arcgis\gis\_impl\_portalpy.py:438: in add_item
>    resp = self.con.post(path, postdata, files)
>..\..\..\..\..\AppData\Local\ESRI\conda\envs\arcgispro-py3-ps\lib\site-packages\arcgis\gis\_impl\_con\_connection.py:1524: in post
>    return self._handle_response(
>..\..\..\..\..\AppData\Local\ESRI\conda\envs\arcgispro-py3-ps\lib\site-packages\arcgis\gis\_impl\_con\_connection.py:1000: in _handle_response
>    self._handle_json_error(data["error"], errorcode)
>_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>
>self = <arcgis.gis._impl._con._connection.Connection object at 0x0000026A223A0B20>
>error = {'code': 400, 'details': [], 'message': 'Item type not valid.', 'messageCode': 'CONT_0113'}
>errorcode = 400
>
>    def _handle_json_error(self, error, errorcode):
>        errormessage = error.get("message")
>        # handles case where message exists in the dictionary but is None
>        if errormessage is None:
>            errormessage = "Unknown Error"
>        # _log.error(errormessage)
>        if "details" in error and error["details"] is not None:
>            if isinstance(error["details"], str):
>                errormessage = f"{errormessage} \n {error['details']}"
>                # _log.error(error['details'])
>            else:
>                for errordetail in error["details"]:
>                    if isinstance(errordetail, str):
>                        errormessage = errormessage + "\n" + errordetail
>                        # _log.error(errordetail)
>    
>        errormessage = errormessage + "\n(Error Code: " + str(errorcode) + ")"
>        raise Exception(errormessage)
>E       Exception: Item type not valid.
>E       (Error Code: 400)
>
>..\..\..\..\..\AppData\Local\ESRI\conda\envs\arcgispro-py3-ps\lib\site-packages\arcgis\gis\_impl\_con\_connection.py:1023: Exception

请问我在哪里可以查看所有允许的Item类型列表?

解决方法

有三种可靠方式查看ArcGIS支持的所有Item类型:

  • 通过ArcGIS Python API直接查询:在已建立GIS连接后,调用gis.content.types属性,该属性会返回当前Portal/Online实例支持的所有Item类型集合,包含类型ID、显示名称等信息。示例代码:
gis = GIS(portal_url, username, password)
# 打印所有支持的Item类型
for item_type in gis.content.types:
    print(f"类型ID: {item_type.id}, 名称: {item_type.name}")
  • 通过ArcGIS Portal/Online网页端查看:登录你的ArcGIS Portal或Online账号,进入内容库后点击「添加项目」,弹出的选项下拉列表即为所有支持的Item类型;也可进入管理界面,在「项目类型」设置板块查看完整列表。
  • 查看本地ArcGIS Python API文档:若使用本地ArcGIS Pro Python环境,可在conda环境的文档目录中查找Item类型相关参考,或在ArcGIS Pro帮助系统中搜索「支持的项目类型」获取详细列表。

注意:图片类文件对应的正确Item类型ID是Image,而非文件后缀名jpg,你可以将data_type设为Image再尝试上传。

内容的提问来源于stack exchange,提问作者MaxDragonheart

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 19:48:12