Mahir Can Pınar
Mahir Can Pınar

Reputation: 11

PYTHON REQUESTS ERROR: ('Connection aborted.', OSError("(10054, 'WSAECONNRESET')"))

I am trying to get data from a web service,working with soap. Until now, I was able to get successfull responses but now my code throws this error. Any ideas on why a working code a day before throws this error now? Note that this is not a public API, your IP needed to be in whitelist to retrieve data.

edit for code:

import requests
headers = {'x-ibm-client-id': "MY KEY",
       'content-type': 'application/soap+xml',
       'accept':'application/xml'}

url="https://api.epias.com.tr/epias/exchange/electricity/balancingMarket"
login="""<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
 <soapenv:Header>
  <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
   <wsse:UsernameToken>
    <wsse:Username>string</wsse:Username>
    <wsse:Password>string</wsse:Password>
    <wsse:Nonce EncodingType="string">string</wsse:Nonce>
    <wsu:Created>string</wsu:Created>
   </wsse:UsernameToken>
   <wsu:Timestamp wsu:Id="string">
    <wsu:Created>string</wsu:Created>
    <wsu:Expires>string</wsu:Expires>
   </wsu:Timestamp>
  </wsse:Security>
 </soapenv:Header>
 <soapenv:Body>
  <dgp:login xmlns:dgp="http://ws.dgpys.deloitte.com"><!-- mandatory -->
   <loginMessage>
    <Password v="MYPASSWORD"></Password>
    <UserName v="MYUSERNAME"></UserName>
   </loginMessage>
  </dgp:login>
 </soapenv:Body>
 """
s=requests.Session()

s.get(url)
res=s.post(url,data=login,headers=headers)

Upvotes: 1

Views: 10339

Answers (1)

timmy turner
timmy turner

Reputation: 98

keep the above code ,you should handle the proxy setting.

import urlparse,urllib2


s=requests.Session()
opener=urllib2.build_opener()
if proxy:

    proxy_params={urlparse.urlparse(url).scheme : proxy}
    opener.add_handler(urllib2.ProxyHandler(proxy_params))
s.get(url)
res=s.post(url,data=login,headers=headers)

if your code used to work, the site might have blocked your IP or don't like your header settings.

Upvotes: 2

Related Questions