Error connecting to WCF service with Python suds - python

I am trying to connect to a WCF web service with Python suds. The link type is:
from suds import Client
url = "http://ipadress/Webservices/WCF/Service.svc?singleWsdl"
client = Client(url)
response = client.services.GetData(username, password)
The error I get comes from the urllib2 library, which is a dependency of suds:
urllib2.URLError: <urlopen error [Errno 11004] getaddrinfo failed>
When I put the url in the browser I get the xml tree of the web service, therefore the link appears to be good. Is it a problem with suds not supporting these types of web services?

Related

WebSocket connection failed: Error during WebSocket handshake: Unexpected response code: 502

We have host python service on the server (no public accessible) which allows HTTPS and Web Socket requests on 4431.To connect to the python service, we have implemented an Azure App Gateway (bind with the domain) with rule - domain:4431 and which will be redirected to the server.
So, the problem is we are facing the following error
502 Bad Gateway - Microsoft-Azure-Application-Gateway/v2
We have observed that request from the browser comes to the AppGW but on server, we are receiving request intermittently.
socketio.run(app, host='0.0.0.0', port=4431, certfile=certs["crt"], keyfile=certs["key"], ssl_version=ssl.PROTOCOL_TLSv1_2)
Our Architecture
Error
Found out, what was causing the issue, we haven't provided root CA Certificate to run server.
socketio.run(app, host='0.0.0.0', port=4431, certfile=certs["crt"], keyfile=certs["key"], ca_certs=certs["CA crt"], ssl_version=ssl.PROTOCOL_TLSv1_2)

InstagramApi using Python: How to set up proxy server?

I am newbie to Instagram Api. I am trying to figure out how to set proxy for InstagramApi using Python. Below is the basic code which I got from github. When I executed this code I got an error. I think I need to include proxy server.
How can I include a proxy server in this?
from instagram.client import InstagramAPI
access_token="*******************************"
client_secret="******************************"
api = InstagramAPI(access_token=access_token, client_secret=client_secret)
recent_media, next_ = api.user_recent_media(user_id="jey07", count=4)
for media in recent_media:
print(media.caption.text)
I am getting below error:
File "C:\Users\Gabriel\AppData\Local\Programs\Python\Python36\lib\socket.py", line 713, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
It's not possible with the current version of python-instagram lib. But to deal with http requests, python-instagram uses httplib2 that allows you to set a Proxy Server : http://httplib2.readthedocs.io/en/latest/libhttplib2.html?highlight=proxyinfo#httplib2.ProxyInfo
You can fork the project, implement the feature and make a pull request.
Alternatively, you can try to use Instagram-API-python library. Proxy seems to be supported : https://github.com/LevPasha/Instagram-API-python/blob/master/InstagramAPI.py#L64

HTTPConnection request socket.gaierror in python

I encountered an error today while trying to retrieve an XML by sending a 'GET' HTTP request.
from httplib import HTTPConnection
import urllib
params = urllib.urlencode({'sK': 'test', 'sXML': 1})
httpCon = HTTPConnection("http://www.podnapisi.net",80)
httpCon.request('GET', '/en/ppodnapisi/search',params)
r1 = httpCon.getresponse()
and here is the error i got:
.....
File "C:\Python27\lib\socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11004] getaddrinfo failed
The XML that I am trying to retrieve HERE
How can I fix this error ?
Thanks in Advance ...
No scheme (http://) in the HTTPConnection constructor:
httpCon = HTTPConnection("www.podnapisi.net",80)
It already knows it's HTTP, it's an HTTPConnection object :)
You accidentally included the protocol prefix in the domain argument to HTTPConnection. You want:
httpCon = HTTPConnection("www.podnapisi.net", 80)
Generally, This error indicates there was a problem resolving the domain name to an IP address. In It might be just intermittent. If the problem persists, check the DNS configuration on your system.
For example, you can set it to use Google's public DNS server. For more information about how to configure your DNS server on Microsoft Windows, refer to Microsoft's knowledge database.

How can I pass a SSL certificate to a SOAP server using SOAPpy / Python

I am building a script to access a HTTPS/TLS TCP site that requires a X.509 certifcate that I have as a .pfx file.
I am using SOAPpy 0.12.5 and Python 2.7 and have started off with code as below,
import SOAPpy
url = "192.168.0.1:5001"
server = SOAPpy.SOAPProxy(url)
# I think I need to pass the cert to server here...
server.callSoapRPC(xxxx)
If I try running this it fails with the following message
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it
Any sugestions how to tie the .pfx certificate to the SOAPproxy?
Thanks
I managed to do it this way:
import SOAPpy
SOAPpy.Config.SSL.cert_file = 'cert_file'
SOAPpy.Config.SSL.key_file = 'key_file'
server = SOAPpy.SOAPProxy(url, config=config)

urllib2 connection timed out error

I am trying to open a page using urllib2 but i keep getting connection timed out errors.
The line which i am using is:
f = urllib2.urlopen(url)
exact error is:
URLError: <urlopen error [Errno 110] Connection timed out>
urllib2 respects robots.txt. Many sites block the default User-Agent.
Try adding a new User-Agent, by creating Request objects & using them as arguments for urlopen:
import urllib2
request = urllib2.Request('http://www.example.com/')
request.add_header('User-agent', 'Mozilla/5.0 (Linux i686)')
response = urllib2.urlopen(request)
Several detailed walk-throughs are available, such as http://www.doughellmann.com/PyMOTW/urllib2/
As a general strategy, open wireshark and watch the traffic generated by urllib2.urlopen(url). You may be able to see where the error is coming from.

Categories

Resources