2

I am trying to create a secure connection to Money.net API using user id and pwd but I am not getting any response back from server. I am using Ipython Notebook for development and I am new to world of Programming and Python :)

import socket
import sys
Server_address = ('api.data.money.net',50010)
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
print sys.stderr, 'connecting to %s port %s' %Server_address
s.connect(Server_address)
####### I pass plain text authentication credentials below #####
username, password, DATA

Nothing happens and server doesn't respond back with 'OK' as expected

I also tried TLS socket.wrap method below but it says "connection timed out"

import socket
import ssl

# SET VARIABLES
#packet, reply = "QS MSFT", ""
HOST, PORT = 'api.data.money.net', 50010

# CREATE SOCKET
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(30)

# WRAP SOCKET
wrappedSocket = ssl.wrap_socket(sock,keyfile=None,server_side=0,
                            ssl_version=ssl.PROTOCOL_TLSv1,                                    cert_reqs=ssl.CERT_NONE,do_handshake_on_connect=True)


# CONNECT AND PRINT REPLY
wrappedSocket.connect((HOST, PORT))


#Plain Text authentication
'username','password'

I get the response

'username','password'

Then i execute the following

packet,reply="QS MSFT",""
wrappedSocket.send(packet)
print wrappedSocket.recv(1280)

I get the following error in the end

SSLError: ('The read operation timed out',)
abhi_phoenix
  • 387
  • 1
  • 5
  • 19

1 Answers1

1

I would expect an API to be exposed over internet using https rather than sockets. Are you sure you have to go that way?

There are a lot of packages to make a secure call with basic authentication. The requests packages is higher level and used in many projects, so that would be your safest bet.

Note that early versions of these libraries simply ignored certificate verification, if it has to be really secure make sure you.

Look at the answers at Python, HTTPS GET with basic authentication.

Community
  • 1
  • 1
  • As per their www.money.net/datafeed document "Note: If you are using a proxy server on your network, our system requires either a standalone SOCKS proxy or a SOCKS proxy in combination with a web proxy. A web proxy which only handles HTTP and HTTPS traffic will not work as our market data connection uses a proprietary TCP protocol that is not compatible with the HTTP protocol. " However as shown above i did try TLS connection using socket wrap but it didnt work too :( – abhi_phoenix Mar 09 '17 at 04:48