我是python中的新手。我已经尝试了几天没有运气:(。 当名称和地址在soap服务器上时,respsonse工作正常。但有时候地址是 - 在肥皂服务器上。我该如何做出---对无回应?
在我的soap.py
中import logging
from suds.client import Client
logging.getLogger('suds.client').setLevel(logging.DEBUG)
from urllib import getproxies
def return_address( country_code, vat_number):
if country_code == None and vat_number == None:
return None
VIES_URL = "http://ec.europa.eu/taxation_customs/vies/checkVatSeice.wsdl"
client = Client(VIES_URL, proxy=getproxies())
response = client.service.checkVat(countryCode= country_code, vatNumber= vat_number)
return response
if __name__== '__main__':
address_returned = return_address( None, None)#
print address_returned
#innan if not "address_returned:
if not address_returned:
print address_returned['name']
print address_returned['address']
和
# -*- coding: UTF-8 -*-
import pymysql.cursors
import sys
import re
import os
from PIL import Image
import base64
import cStringIO
from soap import return_address
if __name__== '__main__':
#
dsn_database = "
dsn_hostname = "localhost"
dsn_port =
dsn_uid =
dsn_pwd =
#dsn_charset='utf8'
conn = pymysql.connect(host=dsn_hostname, user=dsn_uid, passwd=dsn_pwd, db=dsn_database, charset='utf8', use_unicode=True)
cursor=conn.cursor()
cursor.execute("SELECT `uid`, `vat_number`, `country` FROM test")
rows = cursor.fetchall()
num_IDs = len( rows)
cursor.execute("SELECT `uid`, `vat_number`, `company_adress`, `country`, `company_name` FROM oldcompany ")
rows2 = cursor.fetchall()
print rows2
for i in range (num_IDs):
uID = str(rows[i][0])
vat_number = str(rows[i][1])
country_code = str(rows[i][2])
print "check: "
vat_number = vat_number.strip()
country_code = country_code.strip()
response = None
valid = False
if country_code != 'None' and vat_number != 'None':
print 'going to viet for: ', vat_number, country_code
response = return_address( country_code, vat_number)
if response:
valid = response['valid']
company_name = "test" #None
address = "test"
#address1 = response['address']
#############################################################################################
company_name = response['name']
if response and valid and country_code != '--':
#print 'response: '
print 'response: ', response['name'], response['address']
company_name = response['name']
address = response['address']
else:
breaker = 0
print "FOUND: ", address, company_name
print 'IN ELSE'
for j in range(len(rows2)):
vat2 = str(rows2[j][1])
if vat_number == vat2: # match is there
address = str(rows2[j][2])
company_name = str(rows2[j][4])
breaker = 1
#s.encode('utf-8')
print "FOUND: ", vat2, address, company_name
if breaker == 1:
break
#### UPDATE
#print 'before update: ', address, company_name
cursor.execute("UPDATE test SET company_adress = %s , company_name=%s WHERE uid = '" + uID +"'", ( address, company_name))
cursor.execute("UPDATE oldcompany SET company_adress = %s , company_name=%s WHERE vat_number = '" + vat_number +"'", ( address, company_name))
conn.commit()
cursor.execute(“SELECT uid
,invoice_nr
,company_name
,company_adress
FROM test”)
print(“提交后查询:”)
打印(cursor.fetchall())