gpt4 book ai didi

python - 从pyusps解析地址信息

转载 作者:行者123 更新时间:2023-11-28 19:25:51 25 4
gpt4 key购买 nike

我正在使用 Pyusps(Python USPS Api)来验证地址是否确实存在。我创建了一个表单来捕获数据;我很难从 api 接收数据并将其显示在下一页上。任何帮助将不胜感激。

#views.py

def address(args):
address = AddressForm['street']

def city(args):
city = AddressForm['city']

def state(args):
state = AddressForm['state']

def zip5(args):
zip5 = AddressForm['zip_code']


def address_view(request):
if request.method == 'POST':
form = AddressForm(request.POST)
if form.is_valid():
try:
from pyusps import address_information
addr = dict([
('address', {'address': address}),
('city', {'city': city}),
('state', {'state': state}),
('zip5', {'zip_code': zip5}),
])
address_information.verify('API_ID', addr)
a = dict([
('address', '6406 IVY LN'),
('city', 'GREENBELT'),
('state', 'MD'),
('zip5', '20770'),
('zip4', '1441'),
])
c = {'form': a}
return render_to_response('address_change.html', c, context_instance=RequestContext(request))
except ValueError:
pass

else:
form = AddressForm()
c = {'form': form}
return render_to_response('address_change.html', c, context_instance=RequestContext(request))

#models.py
class Address(models.Model):
user = models.ForeignKey(User)
street = models.CharField(max_length=50)
city = models.CharField(max_length=50)
state = models.CharField(max_length=50)
zip_code = models.CharField(max_length=50)


# Pyusps API Documentation
from pyusps import address_information

addr = dict([
('address', '6406 Ivy Lane'),
('city', 'Greenbelt'),
('state', 'MD'),
])
address_information.verify('foo_id', addr)
dict([
('address', '6406 IVY LN'),
('city', 'GREENBELT'),
('state', 'MD'),
('zip5', '20770'),
('zip4', '1441'),
])

最佳答案

我想我看到了你的问题,这个:

addr = dict([
('address', {'address': address}),
('city', {'city': city}),
('state', {'state': state}),
('zip5', {'zip_code': zip5}),
])

应该是:

addr = dict([
('address', address),
('city', city),
('state', state),
('zip5', zip5),
])

关于python - 从pyusps解析地址信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13419995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com