-1

i was able to connect to an external db but while trying to generate a qr code from the result i'm getting this error.

import pymssql, pandas as pd, openpyxl, pyqrcode, os
QRCode(content=b'0001-87L58/1', error='H', version=2, mode='alphanumeric')
Traceback (most recent call last):
  File "C:/Users/MSE/PycharmProjects/qrcode_gen/CIN_from_Server.py", line 25, in <module>
    qr.eps(PIN +'.eps', scale=2.5, module_color='#36C')
  File "C:\Users\MSE\PycharmProjects\Python4everyone\venv\lib\site-packages\pyqrcode\__init__.py", line 624, in eps
    background, quiet_zone)
  File "C:\Users\MSE\PycharmProjects\Python4everyone\venv\lib\site-packages\pyqrcode\builder.py", line 1461, in _eps
    f, autoclose = _get_writable(file_or_path, 'w')
  File "C:\Users\MSE\PycharmProjects\Python4everyone\venv\lib\site-packages\pyqrcode\builder.py", line 924, in _get_writable
    stream_or_path = open(stream_or_path, mode)
FileNotFoundError: [Errno 2] No such file or directory: '0001-87L58/1.eps' 

My code:

import pymssql, pandas as pd, openpyxl, pyqrcode, os

#Connecting to Db using Pymssql library
host = "myHost"
username = "Mine"
password = "mine#$"
database = "external"

conn = pymssql.connect(host, username, password, database)  #connecting string
read_query = " Select * FROM dbo.M_tblPIN WHERE TI = 'A01' "

mycursor = conn.cursor()
mycursor.execute(read_query)
result = mycursor.fetchall()
for item in result:
    PIN = item[12]
    # using pyqrcode to create the barcode
    qr = pyqrcode.create(PIN)
    print(qr)
    qr.eps(PIN + '.eps', scale=5, module_color='#36C')
    qr.eps(PIN + '.eps', background='#eee')

How to generate the qrcode and save it in an external directory?

James Z
  • 12,209
  • 10
  • 24
  • 44
Shegmatech
  • 1
  • 1
  • 2
  • Does this answer your question? [Python open() gives IOError: Errno 2 No such file or directory](https://stackoverflow.com/questions/12201928/python-open-gives-ioerror-errno-2-no-such-file-or-directory) – Qiu Aug 19 '20 at 12:34

1 Answers1

0

last line in traceback is this:

FileNotFoundError: [Errno 2] No such file or directory: '0001-87L58/1.eps'

so the item[12] contains not only a filename, but also a directory name, which does not exist. As such Python is unable to write a file into non-existing directory, and raises an exception. Either create the directory first, or be sure you're in the directory where you think the subdirectory is.

yedpodtrzitko
  • 9,035
  • 2
  • 40
  • 42