× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Craig I made the same mistake when I first started using ibm_db_dbi. It requires no parms. It connects to db2 as the user running the job.

Just import ibm_db_dbi. I choose to import it as db2

Import ibm_db_dbi as db2

conn = db2.connect() #gets you a connection object
cur = conn.cursor() #creates a cursor on your connection
query = "some query string"
cur.execute(query)
results_list = cur.fetchall()


-----Original Message-----
From: OpenSource <opensource-bounces@xxxxxxxxxxxx> On Behalf Of Craig Richards
Sent: Friday, August 24, 2018 9:50 AM
To: IBMi Open Source Roundtable <opensource@xxxxxxxxxxxx>
Subject: Re: [IBMiOSS] Python, adding modules to RPM installs

The e-mail below is from an external source. Please do not open attachments or click links from an unknown or suspicious origin.

Hi John and Jeremy,

Thanks for taking the time to reply, I appreciate it.

I had to install pip3 via RPM, I hadn't noticed it in the list because my eyes are old and it was called python3-pip and not just pip /blush but having installed that and set my current directory to where RPM puts the
installs '/QOpenSys/pkgs/bin' I was able to run pip3 to install
xlsxwriter.

With regard to QSH, I don't do any serious editing in it, I was just using it for a couple of quick tests.
Other than that, for now I've just been using ultraedit to edit script files in the ifs which is good enough for now.
But thanks for the info I'll have a look at some of the options you mentioned.

John, on another subject I was looking at an article you wrote ages ago - the 9 lines of python to produce a spreadsheet from a db2 table.

I can connect easily enough using the ibm_db module and I did that by storing my credentials in a separate config file - so something like:

conn = ibm_db.connect(config.DATABASE_CONFIG['dbname'],
config.DATABASE_CONFIG['user'], config.DATABASE_CONFIG['password'])

And that all works fine and I can successfully work with the database.

But when I've tried connecting with the ibm_db_dbi module as in your example and several others I've seen, I get an error.

Your example (which is several years old I know) does not specify any parameters in the connect() method but other examples I've seen seem to suggest you can connect like this:

conn = ibm_db_dbi.connect(database='*LOCAL')

Which I was hoping might use the credentials of the currently logged on user and connect to the default local database but I just get an error:

python '/home/richarc/p/py6.py'

Traceback (most recent call last):

File "/home/richarc/p/py6.py", line 8, in <module>

conn = ibm_db_dbi.connect(database='*LOCAL')

File "/QOpenSys/QIBM/ProdData/OPS/Python2.7/lib/python2.7/site-packages/ibm_db_dbi.py",
line 648, in connect
return _connect_helper(ibm_db.connect, dsn, user, password, host, database, conn_options)
File "/QOpenSys/QIBM/ProdData/OPS/Python2.7/lib/python2.7/site-packages/ibm_db_dbi.py",
line 639, in _connect_helper
raise _get_exception(inst)

ibm_db_dbi.Error: ibm_db_dbi::Error: Supplied connection object Parameter is invalid

I can see that that seems to be telling me I need to pass a bunch of parameters dsn, user, password, host, database and options.

I haven't had a chance to hunt down the right documentation to see how to specify those parameters, which I'm sure I can find and figure out, I was just hopeful from some of the examples I'd seen that there was a way just to use the local user for those credentials rather than retrieving them from a config file or something.

Thanks again for taking the time to reply.

Best regards,
Craig




On 24 August 2018 at 14:46, Jeremy Meyer <JMeyer@xxxxxxxxxxxxx> wrote:

I echo John's sentiments on QSH. QSH is just hard. Jessie Gorzinski
published a good article on getting started with SSH.
http://ibmsystemsmag.com/blogs/open-your-i/august-2017/
eight-reasons-to-embrace-ssh/

The one prior to that talks about setting up your default shell. I use
Cygwin as my terminal and bash as my shell. Add pudb to that and you
get a pretty good terminal debug environment for Python.

-----Original Message-----
From: OpenSource <opensource-bounces@xxxxxxxxxxxx> On Behalf Of John
Yeung
Sent: Friday, August 24, 2018 8:33 AM
To: IBMi Open Source Roundtable <opensource@xxxxxxxxxxxx>
Subject: Re: [IBMiOSS] Python, adding modules to RPM installs

The e-mail below is from an external source. Please do not open
attachments or click links from an unknown or suspicious origin.

On Fri, Aug 24, 2018 at 5:18 AM Craig Richards
<craig@xxxxxxxxxxxxxxxx>
wrote:
What I'd like to do now is install xlsxwriter into the RPM python3
installation.
I'm not really sure how to do that - do I need to use yum manually
to do that?

No, once Python is installed, the idea is to use pip for everything
related to that installation of Python.

I don't have any of the PASE Pythons to test for myself, but there
should be a pip that is specific to your Python 3.6.6. If you can't
find that, then you can invoke pip not as a standalone command but as
a Python script that is run by the desired Python interpreter. For
example, assuming your path and/or current directory is such that
`python` refers to the Python you want, do

python -m pip install xlsxwriter

Also, on a slightly different note, although the RPM version of
python
3.6.6 works fine for my json pretty print requirement, I notice that
if I run QSH interactively and then /QOpenSys/pkgs/bin/python3 to go
into python it behaves differently to the other installs of python2
and python3 -if I type something and press enter, it takes just the
first letter of what I have typed, if I press enter a second time,
the rest of what I typed appears on the next line down and then runs?

As I said, I can't test this myself, but the preferred way to work
with any of the PASE Pythons is to set up your i to accept SSH
sessions, and then log in that way. You'll then have a much more Unix-like environment.
The 5250 is just not a TTY-style terminal interface, and you really
need that to use PASE effectively (and sanely!).

Sadly, I don't have any tips on how to tell if you are set up for SSH
(other than just trying to connect using PuTTY or similar software),
and more importantly how to set it up if it's not already. But plenty
of others here can chime in because they all use SSH for their PASE work.

John Y.
--
This is the IBMi Open Source Roundtable (OpenSource) mailing list To
post a message email: OpenSource@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/opensource
or email: OpenSource-request@xxxxxxxxxxxx Before posting, please take
a moment to review the archives at https://archive.midrange.com/opensource.

NOTICE: This electronic mail message and any files transmitted with it
are intended exclusively for the individual or entity to which it is
addressed. The message, together with any attachment, may contain
confidential and/or privileged information.
Any unauthorized review, use, printing, saving, copying, disclosure or
distribution is strictly prohibited. If you have received this message
in error, please immediately advise the sender by reply email and
delete all copies.

--
This is the IBMi Open Source Roundtable (OpenSource) mailing list To
post a message email: OpenSource@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/opensource
or email: OpenSource-request@xxxxxxxxxxxx Before posting, please take
a moment to review the archives at
https://archive.midrange.com/opensource.

--
This is the IBMi Open Source Roundtable (OpenSource) mailing list To post a message email: OpenSource@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/opensource
or email: OpenSource-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at https://archive.midrange.com/opensource.

NOTICE: This electronic mail message and any files transmitted with it are intended
exclusively for the individual or entity to which it is addressed. The message,
together with any attachment, may contain confidential and/or privileged information.
Any unauthorized review, use, printing, saving, copying, disclosure or distribution
is strictly prohibited. If you have received this message in error, please
immediately advise the sender by reply email and delete all copies.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.