Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8177971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:39:17+00:00 2026-06-06T23:39:17+00:00

I am trying to see if I can get the python-gnupg module working to

  • 0

I am trying to see if I can get the python-gnupg module working to sign and verify a file using a python script. I have the following code, which does not interpret any errors when called.

However the code prints “unverified” at the end, when I thought that I had signed the file (example.txt).

I must be missing something in the documentation but after I read it this is what I came up with for signing and verifying. Any help please?

import gnupg

gpg = gnupg.GPG(gnupghome="/home/myname") 

stream = open("example.txt", "rb")

signed_data = gpg.sign_file(stream)

verified = gpg.verify_file(stream)

print "Verified" if verified else "Unverified"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T23:39:18+00:00Added an answer on June 6, 2026 at 11:39 pm

    There are a few issues with your code,

    1.) gpg = gnupg.GPG(gnupghome="/home/myname") needs to be gpg = gnupg.GPG(gnupghome="/home/myname/.gnupg")

    2.) You are attempting to verify the stream, using verify_file(stream), however the stream is still a handle to the original, unsigned file. You would first need to either write the signed data to a new file and call verify_file() against a handle to that file, or verify the result sign_file.

    Below is a working example of your demo, using the result of sign_file – but before we get to that, the way to troubleshoot what is happening in your script, you can review the output of stderr on the returned object of the gnupg methods. for example, you can review the result of the signed data by printing out signed_data.stderr. Likewise for return of the verify_file method.

    On to the code –

    import gnupg
    
    gpg = gnupg.GPG(gnupghome="/home/myname/.gnupg")
    
    stream = open("example.txt", "rb")
    
    signed_data = gpg.sign_file(stream)
    
    verified = gpg.verify(signed_data.data)
    
    print "Verified" if verified else "Unverified"
    

    I hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Beginner here trying to get a pipeline working in bash. If somebody can see
I have the following and you can see I am trying to pass this
I'm trying to get simple code working, unfortunately I'm a python beginner. My script
I am trying to run an awk script using python, so I can process
I am trying to get this to work but can't see where I'm going
I am trying to get my VBO to draw, but I can't see anything.
I am trying to print a XML file using lxml and Python. Here is
I am trying to get python-gnupg to work in Jython under PyDev under Eclipse.
I am trying to get a script performance improved, using ThreadPoolExecutor from concurrent.futures. I
I have a python script that runs a subprocess to get some data and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.