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

集成Shopify与FastAPI遇shopify.api_version.VersionNotFoundError求助

Shopify授权集成FastAPI时出现VersionNotFoundError的解决方法

问题描述

我正在将Shopify与FastAPI集成以创建REST API端点,当前尝试通过应用实现卖家授权,代码如下:

# Endpoint to authenticate a seller
@router.post("/authorize", response_class=ORJSONResponse)
def authorize_seller(auth_data: SellerAuth):

    # Start a Shopify session
    shopify.Session.setup(api_key=os.getenv("SHOPIFY_CLIENT_ID"), secret=os.getenv("SHOPIFY_CLIENT_SECRET"))
    
    shop_url = "c56-test-seller.myshopify.com"
    api_version = '2023-07'
    state = binascii.b2a_hex(os.urandom(15)).decode("utf-8")
    # redirect_uri = "http://myapp.com/auth/shopify/callback"
    redirect_uri = "http://127.0.0.1:8082"
    scopes = ['read_products', 'read_orders']

    newSession = shopify.Session(shop_url, api_version)
    auth_url = newSession.create_permission_url(scopes, redirect_uri, state)

    return ORJSONResponse(
        status_code=response_status.HTTP_200_OK,
        content=jsonable_encoder({"auth_url": auth_url}),
    )

但遇到了shopify.api_version.VersionNotFoundError,已在合作伙伴后台将redirect_uri添加至URL列表,尽管'2023-07'是当前稳定版本,错误跟踪提示:

return cls.versions[version]
KeyError: '2023-07'

解决方法

  • 升级Shopify API Python库
    你当前使用的shopify-api-python库版本可能未同步Shopify的2023-07 API版本。先查看当前库版本:

    pip show shopify-api-python
    

    然后升级到最新稳定版:

    pip install --upgrade shopify-api-python
    

    新版本库会包含Shopify最新的API版本列表,解决版本匹配问题。

  • 更换为库支持的API版本
    如果升级库后仍报错,或暂时无法升级,可尝试使用库已支持的稳定版本,比如2024-01或2024-04,这些版本在新版库中必然被支持,且功能覆盖2023-07的核心需求。

  • 临时手动注册API版本(不推荐长期使用)
    若升级不可行,可在创建Session前手动将2023-07版本加入版本列表:

    from shopify.api_version import ApiVersion
    ApiVersion.versions['2023-07'] = {'release_date': '2023-04-01', 'supported': True}
    

    注意此方法可能引发其他兼容性问题,仅作为临时应急方案。

  • 验证店铺支持的API版本
    登录Shopify合作伙伴后台,确认目标店铺是否支持2023-07版本。部分老旧店铺可能限制使用较新的API版本,此时需切换为店铺兼容的版本。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 17:42:45