terça-feira, 23 de fevereiro de 2016
urllib2: urlopen error _ssl.c:320: Invalid SSL protocol variant specified.
urllib2.URLError: <urlopen error _ssl.c:320: Invalid SSL protocol variant specified.>
File "/usr/local/lib/python2.7/dist-packages/suds/client.py", line 521, in __call__
return client.invoke(args, kwargs)
File "/usr/local/lib/python2.7/dist-packages/suds/client.py", line 761, in invoke
return self.send(_parse(msg))
File "/usr/local/lib/python2.7/dist-packages/suds/client.py", line 613, in send
reply = self.options.transport.send(request)
File "/usr/local/lib/python2.7/dist-packages/suds/transport/http.py", line 82, in send
fp = self.u2open(u2request)
File "http_conultaCnpj.py", line 224, in u2open
return url.open(u2request, timeout=tm)
File "/usr/lib/python2.7/urllib2.py", line 404, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 422, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "http_conultaCnpj.py", line 196, in https_open
return self.do_open(self.getConnection, req)
File "/usr/lib/python2.7/urllib2.py", line 1184, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error _ssl.c:320: Invalid SSL protocol variant specified.>
Exception AttributeError: "'NoneType' object has no attribute 'path'" in <function _remove at 0x7f0020003668> ignored
Este erro acontece, devido a isto:
self._finalizar_cripto()
def _finalizar_cripto(self):
xmlsec.cryptoShutdown()
xmlsec.cryptoAppShutdown()
xmlsec.shutdown()
libxml2.cleanupParser()
quinta-feira, 4 de fevereiro de 2016
Odoo - Inativar o Contato ao Inativar a empresa principal - onchange
@api.onchange('active')
def active_partner(self):
if not self.active:
for child in self.child_ids:
child.write({'active': False })
return {'value' : {}, }
def active_partner(self):
if not self.active:
for child in self.child_ids:
child.write({'active': False })
return {'value' : {}, }
Como usar Certificado digital A1 com autenticação via suds python
Origem: http://preaks.weebly.com/bloggy/how-to-use-client-certificate-authentication-with-suds
Extraindo a chave do certificado:
openssl pkcs12 -nocerts -in ClientCert.p12 -out key.pem
Extraindo o certificado:
openssl pkcs12 -clcerts -nokeys -in ClientCert.p12 -out cert.pem
Removendo passphrase da chave:
openssl.exe rsa -in key.pem -out key_nopass.pem
TestaConexao.py
import requests
from suds.client import Client
from suds.transport.http import HttpAuthenticated
from suds.transport import Reply, TransportError
class RequestsTransport(HttpAuthenticated):
def __init__(self, **kwargs):
self.cert = kwargs.pop('cert', None)
HttpAuthenticated.__init__(self, **kwargs)
def send(self, request):
self.addcredentials(request)
resp = requests.post(
request.url,
data=request.message,
headers=request.headers,
cert=self.cert,
verify=True
)
result = Reply(resp.status_code, resp.headers, resp.content)
return result
t = RequestsTransport(cert=('/opt/certificado/cert.pem',
'/opt/certificado/key.pem'))
headers = {"Content-Type": "text/xml;charset=UTF-8", "SOAPAction": ""}
#import pudb;pu.db
wsdl_url = 'https://nfe.prefeitura.sp.gov.br/ws/lotenfe.asmx?WSDL'
client = Client(wsdl_url, transport=t)
Assinar:
Postagens (Atom)