Python Forum
Access online database from python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Access online database from python
#1
Hi,
I am learning python at the moment (codeacademy & learn python android app & a couple of different books) and am also making little programs as I progress along...    

One that I have made currently is a little acronyms dictionary that uses pickle and a .p file to store the dictionary.   However when new words are added by myself they obviously do not show up on the version that I have sent a friend (unless I send her the .p file)

What I'd love to do is store the dictionary online and let it be updated by both of us.  


I was thinking about using an online database perhaps..  is this the way you'd do it?   

I've made an attempt at using pymysql on a .py on my PC but I can't seem to connect to the database on my hostmonster account.  Am I right in thinking I'd need something other than localhost here?  As surely it needs a webaddress in that field to know where the database is?  

Any steer in the right direction would be really appreciated!
Many thanks
D
Reply
#2
Your host provider needs to give you details how to connect to the DB. localhost is alias for server running on your local machine, so if you run the script on your local machine it probably will run, however your friend it will try to connect to server (localhost) on his machine.
Reply
#3
Many thanks for the help...  
They provide this page for remote database connection..  https://my.hostmonster.com/cgi/help/89

Is this what I need to look into?  For host name, it says "use the server IP address"..  however, I'm not sure where to find that.. 
I will ask hostmonster for that info if you think this is the right way to do it..    

One thing I see on that page is that I need to add an IP to gain access..  it would be nice if I wasn't bound to certain computers to use it..
Reply
#4
yes, that's the what you have to look for. contact the support if not able to locate the IP.
Note that you have to white-list the IP address if you want to connect to the database remotely. If you have website hosted on they use localhost in the connection string. If that's a problem you may want to look for different host.
Reply
#5
Flask and DigitalOcean(host of this site) is a good choice.
You may need to spend some time learning this stuff.
Hostmonster is terrible for Python,and cost more than DigitalOcean.
Other Python friendly hosts PythonAnywhere, Heroku.
Reply
#6
Really appreciate the help everyone. Many thanks

I spoke to them and yes the server IP is the shared IP written on the home page of my account..
I've whitelisted my home IP.. and can now load and save a dictionary correctly between the database and python!

However, I feel now the difficulties begin! What would be the best way to organise this..
I'm thinking that the simplest way would be to have upload / download buttons..
The easiest (but most dangerous?) way would be: when upload is pressed, delete all the entries on the remote server and replace them with all the entries of the local dictionary and vice versa for download. (could something go wrong here and lose everything?)
Would it be better to do it on a one by one basis.. ie. upload would look through local dictionary and remote dictionary.. ignore if on both.. but add an entry if in local_dict but not on remote_dict... etc...

PS.. thanks I will look into other hostings eventually.. I've always been happy with hostmonster personally as I have only needed a very basic html/css website. Perhaps that will change now I've started to learn to code.. I suppose instead of a .exe file running the python script.. I could have made the program on a web page.. and then I could have used the "local" host setting? Is this what you mean by hostmonster being no good for that? Is it not possible to do something like that on hostmonster?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Run a Function?: Trouble with Online Python Course webmanoffesto 3 987 Aug-18-2022, 10:14 PM
Last Post: deanhystad
Question Embedding a python file online Dreary35 0 1,513 Jun-10-2021, 05:05 PM
Last Post: Dreary35
  Can't access the net using Python's Selenium module ShishirModi 2 2,039 Jul-21-2020, 06:03 AM
Last Post: ShishirModi
  python doc edit and run online? luckrill 0 1,570 Jul-09-2020, 01:28 PM
Last Post: luckrill
  Online python repl? Gribouillis 4 37,695 Apr-09-2020, 12:19 PM
Last Post: Gribouillis
  Using online python for course, How do I open a File that's a link? WhatsupSmiley 1 2,517 Mar-20-2020, 06:56 AM
Last Post: buran
  Python for MS Access DB Kundan 0 1,864 Feb-20-2020, 08:27 AM
Last Post: Kundan
  Access list items in Python kamaleon 2 2,330 Dec-31-2019, 11:10 AM
Last Post: kamaleon
  How retrieve sqlite3 database saved image and access in python3 tao01 1 2,456 Dec-22-2018, 09:04 PM
Last Post: Larz60+
  Error in running MS Access Database connection code pyuser1 4 7,653 Feb-01-2018, 08:28 PM
Last Post: pyuser1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020