2

Newbie here, looking for advice on which technology I should use for my particular project. Not looking for code per se, just opinions. Here's an ugly diagram of what I'm trying to achieve:

[local Python app] <--ADVICE NEEDED HERE--> [hosted web server]

So from above, I'm looking for the technology that will allow my local app to communicate with the hosted web server. Here's the pitfall: I can't use sockets as I'm on a shared hosting plan and my hosting company restricts this. IRC is also denied. I know, makes it a bit tricky.

So choices do I have left? Here's some ideas I had:

  1. Both local app and server poll a MySQL db for changes, and either can makes changes (I really don't like the idea of polling however, and doesn't seem like a secure solution)
  2. Do some sort of remote http post to get data to the server (possible?), then poll some file on the server for commands
  3. Run a web server locally, write data a text file locally, then have hosted server poll file for changes (I'm really trying to avoid running a web server locally for security reasons).

Any ideas without having to poll? Thanks.

  • Talking to a MySQL server involves using a socket. Making an HTTP POST involves using a socket. Any application that is going to connect to your local web server is going to use a socket to do so. Are you sure you can't use sockets? – Jean-Paul Calderone Nov 19 '11 at 20:49

2 Answers2

3

Maybe paramiko could be a good solution for your problem. I used paramiko for some project I had half a year ago, here is the part of my code where I connected with another computer/server and executed a simple python file:

import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
IP = '...'
username = '...'
password = '...'
ssh.connect(IP, username, password)
stdin, stdout, stderr = ssh.exec_command('python hello.py')
ssh.close()

stdin, stdout and sdterr are lists with the inputs/outputs of the command you executed.

Here is some good information about paramiko: http://jessenoller.com/2009/02/05/ssh-programming-with-paramiko-completely-different/

juliomalegria
  • 24,229
  • 14
  • 73
  • 89
  • Thanks, this is actually a very nice idea, and the package comes bundled on my web host. However for whatever reason I couldn't get a SSH connection with paramiko (even though I used same credentials through PuTTY and it worked just fine). Maybe my host is blocking the connection? I'll look into it a bit more. –  Nov 19 '11 at 20:32
  • don't forget this: `ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())`, it may be the problem. Have you read the blog? it's actually quite complete – juliomalegria Nov 19 '11 at 20:37
1

Not sure if I understood all of your specs correctly, but the first thing that would come to my mind is using RESTful webservice.

Here you can find a StackOverflow question that offers some insight in implementing them with python.

Community
  • 1
  • 1
mac
  • 42,153
  • 26
  • 121
  • 131