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

如何解决TypeError: _get_unique_zone()缺少必填参数'shortcut_id_y'问题

问题修复方案

核心错误原因

你没有正确实例化TimezoneFinder类,直接将类本身当做实例使用,导致方法参数匹配逻辑异常。你之前遇到的需要手动填充self参数的报错,本质也是这个问题导致的。

具体修改点

  • 实例化TimezoneFinder类,将tf = TimezoneFinder改为tf = TimezoneFinder()
  • 去掉offset函数中多余的self参数,直接通过实例调用certain_timezone_at方法,不需要手动传self
  • 修正最后打印语句的变量名错误,前面定义的变量是Correction,不要误用未定义的GMTcor

修复后完整代码

from geopy.geocoders import Nominatim
from datetime import timedelta
from pytz import timezone
import pytz
import datetime
from timezonefinder import TimezoneFinder

address = input("Insert place: ")
geolocator = Nominatim(user_agent="Time Correction Calculator")
location = geolocator.geocode(address)
print(location.address)

t = input("Insert time (hh:mm): ")
(h, m) = t.split(':') 
time_in = int(h) * 60 + int(m) 


date_input = input("Insert date (dd.mm.yyyy): ")

utc = pytz.utc
# 正确实例化TimezoneFinder类
tf = TimezoneFinder()

def offset(target):
    today = datetime.datetime.strptime(date_input, '%d.%m.%Y') 
    # 直接通过实例调用方法,自动填充self
    tz_target = timezone(tf.certain_timezone_at(lat=target['lat'], lng = target['lng']))
    today_target = tz_target.localize(today)
    today_utc = utc.localize(today)
    return (today_utc - today_target).total_seconds() / 3600 

City = dict({'lat' : location.latitude, 'lng' : location.longitude})

realTime : float = location.longitude * 4 
realTime = round(realTime)

Correction = time_in - offset(City) * 60 + realTime 
# 修正变量名与参数写法
print(str(timedelta(minutes = Correction))[:-3])

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.01 22:06:03