Cannot make connection to accdb file using python

0 votes

I am writing a script that needs to make a connection to a microsoft access .accdb file and extract data from it.

Here is a snippet of what I am doing?

import pypyodbc
pypyodbc.lowercase = False

conn = pypyodbc.connect(
       r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};' +
       r'DBQ=file.accdb;'
       )
cur = conn.cursor()

I get the following error:

    raise Error(state,err_text)
pypyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified')

I have installed the drivers for ODBC as instructed in https://docs.microsoft.com/en-us/sql/connect/python/pyodbc/step-1-configure-development-environment-for-pyodbc-python-development

But the error persists, any idea what should I do or where I am going wrong?

Sep 21, 2018 in Python by aryya
• 7,450 points
616 views

1 answer to this question.

0 votes

key is just a variable name.

for key in d:

will simply loop over the keys in the dictionary, rather than the keys and values. To loop over both key and value you can use the following:

For Python 2.x:

for key, value in d.iteritems():

For Python 3.x:

for key, value in d.items():

To test for yourself, change the word key to poop.

For Python 3.x, iteritems() has been replaced with simply items(), which returns a set-like view backed by the dict, like iteritems() but even better. This is also available in 2.7 as viewitems().

The operation items() will work for both 2 and 3, but in 2 it will return a list of the dictionary's (key, value) pairs, which will not reflect changes to the dict that happen after the items() call. If you want the 2.x behavior in 3.x, you can call list(d.items()).

answered Sep 21, 2018 by charlie_brown
• 7,720 points

Related Questions In Python

0 votes
0 answers

Cannot make connection to .accdb file using python

I am writing a script that needs ...READ MORE

Jun 7, 2018 in Python by aryya
• 7,450 points
1,650 views
0 votes
1 answer

Cannot make connection to .accdb file using python

That link has instructions for connecting to ...READ MORE

answered Oct 5, 2018 in Python by Priyaj
• 58,090 points
537 views
0 votes
1 answer

Python using basicConfig method to log to console and file

I can't reproduce it on Python 3.3. ...READ MORE

answered Aug 14, 2018 in Python by aryya
• 7,450 points
867 views
0 votes
1 answer

Python using basicConfig method to log to console and file

Try this working fine(tested in python 2.7) ...READ MORE

answered Aug 27, 2018 in Python by Priyaj
• 58,090 points
9,566 views
0 votes
1 answer

How to download a file over HTTP using Python?

In Python 2, use urllib2 which comes ...READ MORE

answered Oct 18, 2018 in Python by SDeb
• 13,300 points
656 views
+1 vote
1 answer

How to read hdfs file using python?

subprocess.Popen(["hadoop", "fs", "-cat", "/path/to/myfile"], stdou ...READ MORE

answered Dec 7, 2018 in Python by Omkar
• 69,210 points
5,401 views
0 votes
1 answer

How to check latest change time of each file using glob in python?

You can get the changing time from ...READ MORE

answered Jan 2, 2019 in Python by Omkar
• 69,210 points
1,157 views
0 votes
1 answer

Need help extracting a schema to make use for an avro file in Python

Hi, nice question. So what I daily use ...READ MORE

answered Jan 10, 2019 in Python by Nymeria
• 3,560 points
4,555 views
+2 votes
2 answers

How to make a laplacian pyramid using OpenCV python?

down voteacceptTheeThe problem is that you're iterating ...READ MORE

answered Apr 3, 2018 in Python by charlie_brown
• 7,720 points
4,478 views
+2 votes
3 answers

How can I play an audio file in the background using Python?

down voteacceptedFor windows: you could use  winsound.SND_ASYNC to play them ...READ MORE

answered Apr 4, 2018 in Python by charlie_brown
• 7,720 points
12,913 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP