[Tutor] Python "password" securely hashed in script

2016-04-27 Thread Paul Smith
So creating small programs that automate my day specifically logins, how
can one "hash" or hide the user and pass items in the python script itself?
I need to prevent someone from easily seeing or accessing these if they
happen to gain access to my python files. Thanks in advance.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] syntax error when attempting simple urllib.request.urlopen item

2013-07-10 Thread Paul Smith
Tutor-

Ok newbie to coding here attempting to build controlled web scraper and
have followed several books-tutorials and am failing at step one.

This is the 3.3.1 code I am trying to run..
===
import urllib.request

htmltext = urllib.request.urlopen("http://google.com";).read

print htmltext
===
Other version...
===
#try py url open 7

import urllib.request
res = urllib.request.urlopen('http://python.org/')
html = res.read()
print = html
close res
input = ("Press enter to exit")
===

so when I run what I think is proper 3.3.1 python code it hangs up with
syntax error with the idle shell red highlighting the last print reference
i.e. "htmltext"  or "html".

What is this humble newbie not getting?

Best regards,

Paul S
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Timestamp issues when importing from FireFox sqlite field

2013-07-18 Thread Paul Smith
All-

Newb here so apologies upfront.

Attempting timestamp translation via python importing info from sqlite
datetime item in firefox ,'1369751000393000'. Typical unix date time
translation fails. I noted micro second addition but even
'1369751000393000' / 1e6 does not get a chew-able range, at least in python
datetime module. Any suggestions?

Best regards,

Paul

Failing code examples:

>>> import datetime
>>> print
datetime.datetime.fromtimestamp(int("1369751000393000")).strftime('%Y-%m-%d
%H:%M:%S')

Traceback (most recent call last):
  File "", line 1, in 
print
datetime.datetime.fromtimestamp(int("1369751000393000")).strftime('%Y-%m-%d
%H:%M:%S')
ValueError: timestamp out of range for platform localtime()/gmtime()
function

microseconds /1e6?

>>> import datetime
>>> print
datetime.datetime.fromtimestamp(int("1369751000393000/1e6")).strftime('%Y-%m-%d
%H:%M:%S')

Traceback (most recent call last):
  File "", line 1, in 
print
datetime.datetime.fromtimestamp(int("1369751000393000/1e6")).strftime('%Y-%m-%d
%H:%M:%S')
ValueError: invalid literal for int() with base 10: '1369751000393000/1e6'
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] sqlite3 woes opening Moz, FFox sqlite db with only the inevitable 'DatabaseError: file is encrypted or is not a database' occurring...

2013-07-23 Thread Paul Smith
title = three days lost and counting...

Thanks in advance all:

Ok- I want to work with data in FFox, specifically a sqlite db found here..

'C:\Users\Hive2\AppData\Roaming\Mozilla\Firefox\Profiles\zabt0uq4.default\places.sqlite'

...more specifically my FFox history found in a table 'moz_places'.

Running Py 2.7.5 on a windows 7-64 machine and after days of
*consulting -*google; various-boards ;stackoverflow;
py.org; sqlite.org; mingw32?(prereq. for sqlite v. 2.6.3?); sphynx?(another
prereq. for I forget); and *addressing* - possible version differences
between sqlite3 and FFoxdb; file path confirmation; db creation - query
using sqlite3(successful); etc. etc.

We end up here...

import sqlite3 as lite
import sys
import os

print ("sqlite version info1:",lite.version)##clunky version confirm
print ("sqlite version info2:",lite.sqlite_version,"\n")##clunk's cousin

mypath =
os.path.realpath("C:\\Users\\Hive2\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\zabt0uq4.default\\places.sqlite")
mydb = (mypath)## I'm trying to confirm the path to the friggin' thing
print ("This is my db path""\n"+(mydb))
con = None
con = lite.connect(mydb)
with con:
cur = con.cursor()
cur.execute("SELECT * FROM 'moz_places'")## it is a table in places.sqlite
seems apropos
print (con.fetchall()) ## print it all?
con.close()

Which produces...

Python 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)]
on win32
Type "copyright", "credits" or "license()" for more information.
>>>  RESTART

>>>
('sqlite version info1:', '2.6.0')
('sqlite version info2:', '3.6.21', '\n')
This is my db path
C:\Users\Hive2\AppData\Roaming\Mozilla\Firefox\Profiles\zabt0uq4.default\places.sqlite

Traceback (most recent call last):
  File "E:\pyurlseek\zedpathconfirm.py", line 15, in 
cur.execute("SELECT * FROM 'moz_places'")
DatabaseError: file is encrypted or is not a database

I just want to print out the table (or anything from the FFox db just to
prove it is being opened/accessed?!)

I am sure it is a simple error but being a real newb that I am I cannot
escape the dreaded 'DatabaseError: file is encrypted or is not a database',
time and time again.

Help please

Thanks in advance,

PSmith

Additional items: no I did not have FFox open when running; yes I can
access the FFox sqlite db from 3 other programs like SQLite Expert etc. yes
I do need some sleep now so, ciao.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Newbie question. Is it possible to run/call a python2.7 program and reference results from/in python3.3?

2013-09-13 Thread Paul Smith
Attempting a simple web crawler in python3, browse a url -
collect/clean/produce valid url list from a url; random choice from valid
url list; visit new url repeat process - collect/clean/produce valid url
list from new url...

So there are many tools out there but mechanize and scrapy 3rd party
modules seem to produce the best results; however nothing like these exist
for Python3. I get close but cannot produce the clean simple url results in
python3

my borrowed bastardized python2.7 code producing clean url list from
"nytimes" example:
###

#MechSnake2

import urllib
import mechanize
import cookielib
from bs4 import BeautifulSoup
import urlparse
# Browser
br = mechanize.Browser()
# Cookie Jar
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
# Browser options
br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
# Follows refresh 0 but not hangs on refresh > 0
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
# debugging messages
br.set_debug_http(True)
br.set_debug_redirects(True)
br.set_debug_responses(True)
# User-Agent Not a Robot here spoof Mozilla coolness
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US;
rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
url = ("http://www.nytimes.com";)
br.open(url)
for link in br.links():
newurl = urlparse.urljoin(link.base_url, link.url)
b1 = urlparse.urlparse(newurl).hostname
b2 = urlparse.urlparse(newurl).path
print "http://"+b1+b2

###
Works like a charm!

But now go do the same in python3? I am stumped...

Most of the other project code I am working on is in Python3 and works
great! I can produce everything above except the last parse join cleaning
process (urllib.request.Request(url, headers = Mozilla/5.0 etc...for
spoofing) but then it fails to produce the same clean list because of the
Mechanize mojo producing link info that easily allows the parse join
cleaning process at the end.

So can one call the python27 program and use results in python33?

Thank you in advance!

Another nightmare is stripping-cleaning google search results into clean
url lists... but I will defer to another post for that mess.

Thanks again in advance

Paul Smith

+++

Two Kinds of Intelligence

There are two kinds of intelligence: one acquired,
as a child in school memorizes facts and concepts
from books and from what the teacher says,
collecting information from the traditional sciences
as well as from the new sciences.


With such intelligence you rise in the world.
You get ranked ahead or behind others
in regard to your competence in retaining
information. You stroll with this intelligence
in and out of fields of knowledge, getting always more
marks on your preserving tablets.


There is another kind of tablet, one
already completed and preserved inside you.
A spring overflowing its springbox. A freshness
in the center of the chest. This other intelligence
does not turn yellow or stagnate. It's fluid,
and it doesn't move from outside to inside
through conduits of plumbing-learning.


This second knowing is a fountainhead
from within you, moving out.

Mewlana Jalaluddin Rumi

+++
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Protecting username - password items in python3.3

2013-10-10 Thread Paul Smith
Ok experts I need to protect username and password items in some Python3.3
code I am writing.

Let me clarify, I don't care here about protecting the program itself i.e.
using

else:
   main()

to work around my username password input, I simply don't want to reveal
username and password info.

I see md5, hashlib etc. but my program will be up against some BIG CORPS
and I need to make it as painful a process possible for someone to get
username(typically email) and password information from my program.

I am considering using subprocess to achieve this if necessary.

Thanks in advance!

Paul Smith
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Protecting username - password items in python3.3

2013-10-10 Thread Paul Smith
I am automating my email login to yahoo... I run my python script injecting
username and password into the login fields... I run my own filters grab
only the information I want... Not a new concept just a new twist I am
working on... I need to keep the username and password info in my python
code hashed or encrypted somehow without referencing an outside source or
file. I don't care about the program being locked down, we intend on
githubbing it eventually, I just need the ability to protect any username
or password items written in the code. Is this possible?

No one is out to get us or else they would already have us, lol. Ideas have
consequences and though not nefarious it could be easily uglified um just
think automated function married to a password cracker. I just know that I
want to protect any and all information like real email addresses or
passwords folks may use with our script.

-Paul


On Thu, Oct 10, 2013 at 5:49 PM, Oscar Benjamin
wrote:

> On 10 October 2013 22:28, Paul Smith  wrote:
> > Ok experts I need to protect username and password items in some
> Python3.3
> > code I am writing.
>
> I'm not an expert on this subject but...
>
> > Let me clarify, I don't care here about protecting the program itself
> i.e.
> > using
> >
> > else:
> >main()
> >
> > to work around my username password input, I simply don't want to reveal
> > username and password info.
>
> I have no idea what the above means.
>
> > I see md5, hashlib etc. but my program will be up against some BIG CORPS
> and
> > I need to make it as painful a process possible for someone to get
> > username(typically email) and password information from my program.
>
> What do you mean by "BIG CORPS"? Is someone out to get you?
>
> > I am considering using subprocess to achieve this if necessary.
>
> I still don't really understand what you mean. The easiest way to
> protect your program from leaking passwords is just to not store any
> passwords. Presumably you also want to store them in some form in
> order to do something useful though?
>
> Do you want to store the passwords so that they can be recovered? Or
> just so they can be checked against to see if a password entered later
> matches? Are you also trying to hide some other data from the "BIG
> CORPS". Perhaps if you could show a small demo script that does
> approximately what you're thinking but indicating the parts currently
> missing I might understand what you mean.
>
>
> Oscar
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Module? Error handling specific to SQLite3

2014-09-26 Thread Paul Smith
Ok Tutor help please...

Early stages messing with module sqlite3 in python3.4. I am successful in
creating sqlite tables of my own and interacting with other sqlite tables,
however in refining the code from a purely "it can do it" stage to a more
stable working piece of code I run into this problem.

I call the correct sqlite3 items and create table D to which I add or
'amend' specific information from tables A and Z.

However since the table is already created the line of code that created
the table subsequently kicks out this error when the program runs again.

Traceback (most recent call last):
  File "C:\Users\Thechives\Desktop\pyweather\AlphaItems\
weathercodetrial1.2.py", line 206, in 
cur.execute('''CREATE TABLE "D" AS SELECT weather_current FROM
"todays_weather" WHERE weather_current IS NOT NULL''')
sqlite3.OperationalError: table "D" already exists

So how does one handle the error or ignore the creation portion of the
program once the table is created?

Python exception handling has not helped, Try - Except - although I am
mashing it I am sure. I believe since we are actually engaging sqlite via
python at this point in the code it should be a sqlite error handler or
some such. So simple and yet it eludes my noobile mind.

Thanks in advance,

Paul
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor