I can't figure out why this doesn't work. Any ideas appreciated.
conn = MySQLdb.connect (db = "vocab")
cursor = conn.cursor ()
cursor.execute ("SELECT VERSION()")
row = cursor.fetchone ()
print "server version:", row[0]
cursor.close ()
conn.close ()
gives:
server version: 5.0.44-log
but
import defs
conn = MySQLdb.connect (defs.connect)
cursor = conn.cursor ()
cursor.execute ("SELECT VERSION()")
row = cursor.fetchone ()
print "server version:", row[0]
cursor.close ()
conn.close ()
where defs.py is
connect = 'db = "vocab"'
gives:
Traceback (most recent call last):
File "./add_words", line 17, in ?
conn = MySQLdb.connect (defs.connect)
File "/usr/lib/python2.4/site-packages/MySQLdb/__init__.py", line
74, in Connect
return Connection(*arg s, **kwargs)
File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py" ,
line 170, in __init__
super(Connectio n, self).__init__( *args, **kwargs2)
_mysql_exceptio ns.OperationalE rror: (2005, 'Unknown MySQL server host
\'db = "vocab"\' (3)') 3 1646
I'm new to programming and I'm trying to find some answers. I wrote a few
python cgi scripts for my website all of which access a mysql db on
'localhost'. My question is, Is it a bad idea to have my username and
password for my db coded in my script? Is there a better way to make sure
that information can't be acessed? Obviously I wan't to make sure that my
*.py can't be downloaded from /cgi-bin and give anyone access to my db's.
Cory
On 29 dic, 20:31, int32...@yahoo. com wrote:
I can't figure out why this doesn't work. Any ideas appreciated.
conn = MySQLdb.connect (db = "vocab")
cursor = conn.cursor ()
cursor.execute ("SELECT VERSION()")
row = cursor.fetchone ()
print "server version:", row[0]
cursor.close ()
conn.close ()
gives:
server version: 5.0.44-log
but
import defs
conn = MySQLdb.connect (defs.connect)
[...]
where defs.py is
connect = 'db = "vocab"'
gives:
Traceback (most recent call last):
* * * * _mysql_exceptio ns.OperationalE rror: (2005, 'Unknown MySQL server host
\'db = "vocab"\' (3)')
Try this:
defs.py:
dbname = "vocab"
import defs
conn = MySQLdb.connect (db=defs.dbname )
BTW, please read the Style Guide at http://www.python.org/dev/peps/pep-0008
- in particular, I feel space before an opening parens rather
annoying. But it's just a matter of style.
--
Gabriel Genellina
On Dec 29, 6:05 pm, Dennis Lee Bieber <wlfr...@ix.net com.comwrote:
On Sat, 29 Dec 2007 15:31:30 -0800 (PST), int32...@yahoo. com declaimed
the following in comp.lang.pytho n:
I can't figure out why this doesn't work. Any ideas appreciated.
conn = MySQLdb.connect (db = "vocab")
This is a keyword parameter association, the parameter named "db" is
given the string value "vocab".
import defs
conn = MySQLdb.connect (defs.connect)
where defs.py is
connect = 'db = "vocab"'
This is a string. You'd get the same error using:
conn = MySQLdb.connect ('db="vocab"')
as you are giving the entire string to whatever the first defined
parameter in .connect() is...
Change defs.py to:
-=-=-=-=-
connect = { "db" : "vocab" }
and change the connection to read:
-=-=-=-=-
conn = MySQLdb.connect (**defs.connect )
to force keyword unpacking of the dictionary
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfr...@ix.netc om.com wulfr...@bestia ria.com HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-a...@bestiaria. com) HTTP://www.bestiaria.com/
Thanks. This works great. As a side note, it can also be extended so
that if defs.py is
connect = { "host" : "localhost" , "user" : "joey", "db" : "vocab" }
the MySQLdb.connect (**defs.connect ) still works. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jason Charalambides |
last post by:
Is there a way I can import a given value to a variable from the main form
to a module? I wanted to have some routines that are repeated set in a
module subroutine. However, the value of a variable I need to use in the
equations are not read and the equation's result is erroneous. So if I have
a variable to which a value was assigned in the form how can I set it to
have the same value in the module?
|
by: steve |
last post by:
Hello,
I am trying to import an image file into a form. This would be a
persons picture saved in the same directory for every unique record.
I don't have any problems making an action button to open the
directory where the images are but I am having problems putting the
images in the form and also linking a field in a table to this image.
I would rather not have the images saved in access2000 but simple
linked to the file in the directory...
|
by: Peter Frost |
last post by:
Please help
I don't know if this is possible but what I would really like to do is
to use On Error Goto to capture the code that is being executed when
an error occurs.
Any help would be much appreciated.
Thanks in advance
|
by: rshepard |
last post by:
I'm stymied by what should be a simple Python task: accessing the value of
a variable assigned in one module from within a second module. I wonder if
someone here can help clarify my thinking. I've re-read Chapter 16 (Module
Basics) in Lutz and Ascher's "Learning Python" but it's not working for me.
In one module (the "source"), variablePage.py, three wxPython widgets
display values that are assigned to variables: curVar, UoDlow, and...
|
by: rs387 |
last post by:
Hi,
I've found the following behaviour on importing a variable from a
module somewhat odd. The behaviour is identical in Python 2.5 and
3.0b2.
In summary, here's what happens. I have a module, oddmodule.py
(below), that defines a variable, OddVariable, by assigning a value A
to it. The file I execute, mainfile.py, imports and re-binds
OddVariable to a value B. I have two test modules which import the
| |
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |