Re: [Tutor] Help with python-gnupg
Becky Mcquilling wrote: If anyone is familiar with python-gnupg, I am having some difficulty with the syntax. I've tried the following: When dealing with third party packages, unless it is an extremely well-known package like numpy or nltk, it is usually a good idea to link to the project's home page. Do you mean this project? http://packages.python.org/python-gnupg/ Reading the documentation, I think either of these should work: #1 encrypt data in a file input_file = open('c:/test/filename.txt', 'r') # notice that you open the file, but do not read from it. encrypted_data = gpg.encrypt_file(input_file, 'ladym...@gmail.com', output='c:/gpg_test/data.gpg2') #2 encrypt data from a string data = open('c:/test/filename.txt', 'r').read() encrypted_data = gpg.encrypt_file(data, 'ladym...@gmail.com', output='c:/gpg_test/data.gpg2') It looks like the problem you have is that you are passing the output file object, instead of just the file name. If this doesn't solve your problem, please post the exact error message in full, including the traceback, with the exact code you are using. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with python-gnupg
Thanks, everyone: Your suggestions worked. I will make sure to include full information next time. Becky On Sat, Mar 12, 2011 at 12:14 AM, Steven D'Aprano st...@pearwood.infowrote: Becky Mcquilling wrote: If anyone is familiar with python-gnupg, I am having some difficulty with the syntax. I've tried the following: When dealing with third party packages, unless it is an extremely well-known package like numpy or nltk, it is usually a good idea to link to the project's home page. Do you mean this project? http://packages.python.org/python-gnupg/ Reading the documentation, I think either of these should work: #1 encrypt data in a file input_file = open('c:/test/filename.txt', 'r') # notice that you open the file, but do not read from it. encrypted_data = gpg.encrypt_file(input_file, 'ladym...@gmail.com', output='c:/gpg_test/data.gpg2') #2 encrypt data from a string data = open('c:/test/filename.txt', 'r').read() encrypted_data = gpg.encrypt_file(data, 'ladym...@gmail.com', output='c:/gpg_test/data.gpg2') It looks like the problem you have is that you are passing the output file object, instead of just the file name. If this doesn't solve your problem, please post the exact error message in full, including the traceback, with the exact code you are using. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with python-gnupg
On Sat, Mar 12, 2011 at 1:39 AM, Becky Mcquilling ladymcse2...@gmail.com wrote: If anyone is familiar with python-gnupg, I am having some difficulty with the syntax. I've tried the following: f = open('c:/test/filename.txt', 'r') datae = gpg.encrypt_file(f.read(), 'ladym...@gmail.com', output=open('c:/gpg_test/data.gpg2', 'w')) or file_to_encrypt = open('c:/gpg_test/data.gpg2', 'w') datae = gpg(f.read(), 'ladym...@gmail.com', output=file_to_encrypt) Either way, I can't get the output written to a file, it gives me an error: Traceback (most recent call last): File pyshell#65, line 1, in module datae = gpg.encrypt_file(f.read(), 'becky...@google.com', output=open('c:/test/data.gpg2', 'w')) File C:\Python27\lib\site-packages\gnupg.py, line 583, in encrypt_file if os.path.exists(output): File C:\Python27\lib\genericpath.py, line 18, in exists os.stat(path) TypeError: coercing to Unicode: need string or buffer, file found This seems to say it needs a string or buffer, but a file was found. Which says to me, you need to convert the file that is found to a string before passing it as a parameter to a function. It might be that output needs to be a string before it is used, so read the file and string it. It's just a guess from what I see though. Any thoughts? Would reallly appreciate the help. If you aren't familiar with this and know of resources, it would be awesome. Becky ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- According to theoretical physics, the division of spatial intervals as the universe evolves gives rise to the fact that in another timeline, your interdimensional counterpart received helpful advice from me...so be eternally pleased for them. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with python-gnupg
On Sat, Mar 12, 2011 at 2:07 AM, David Hutto smokefl...@gmail.com wrote: As a matter of fact, looking at them with know *no* knowledge of the module, it says it's a typeerror, and that it expects string or buffer, but gets file. If this is the same error in both instances, then it's that output needs to be a string or buffer, so just string either the datae variable, or the output variable. -- According to theoretical physics, the division of spatial intervals as the universe evolves gives rise to the fact that in another timeline, your interdimensional counterpart received helpful advice from me...so be eternally pleased for them. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor