<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic PGP decryption in python file in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/pgp-decryption-in-python-file/m-p/124684#M47242</link>
    <description>&lt;P&gt;The same decryption code works in notebook, but fails in python file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import gnupg&lt;BR /&gt;from pyspark.dbutils import DBUtils&lt;/P&gt;&lt;P&gt;dbutils = DBUtils(spark)&lt;/P&gt;&lt;P&gt;gpg = gnupg.GPG()&lt;/P&gt;&lt;P&gt;decryption_key = dbutils.secrets.get(secret_scope, secret_name)&lt;BR /&gt;gpg.import_keys(decryption_key)&lt;/P&gt;&lt;P&gt;input_file_path = f"/Volumes/{catalog}/{schema}/{volume}/{folder}/{file}.csv.pgp"&lt;/P&gt;&lt;P&gt;with open(input_file_path, 'rb') as f:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; encrypted_data = f.read()&lt;/P&gt;&lt;P&gt;decrypted_data = gpg.decrypt(encrypted_data)&lt;/P&gt;&lt;P&gt;if decrypted_data.ok:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; print("Ok")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, in notebook it's Ok. But In python file I receive&amp;nbsp;WARNING:gnupg:FAILURE status emitted from gpg process: decrypt 4294967295. And the&amp;nbsp;decrypted_data is empty.&lt;/P&gt;</description>
    <pubDate>Wed, 09 Jul 2025 16:50:50 GMT</pubDate>
    <dc:creator>TetianaDromova</dc:creator>
    <dc:date>2025-07-09T16:50:50Z</dc:date>
    <item>
      <title>PGP decryption in python file</title>
      <link>https://community.databricks.com/t5/data-engineering/pgp-decryption-in-python-file/m-p/124684#M47242</link>
      <description>&lt;P&gt;The same decryption code works in notebook, but fails in python file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import gnupg&lt;BR /&gt;from pyspark.dbutils import DBUtils&lt;/P&gt;&lt;P&gt;dbutils = DBUtils(spark)&lt;/P&gt;&lt;P&gt;gpg = gnupg.GPG()&lt;/P&gt;&lt;P&gt;decryption_key = dbutils.secrets.get(secret_scope, secret_name)&lt;BR /&gt;gpg.import_keys(decryption_key)&lt;/P&gt;&lt;P&gt;input_file_path = f"/Volumes/{catalog}/{schema}/{volume}/{folder}/{file}.csv.pgp"&lt;/P&gt;&lt;P&gt;with open(input_file_path, 'rb') as f:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; encrypted_data = f.read()&lt;/P&gt;&lt;P&gt;decrypted_data = gpg.decrypt(encrypted_data)&lt;/P&gt;&lt;P&gt;if decrypted_data.ok:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; print("Ok")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, in notebook it's Ok. But In python file I receive&amp;nbsp;WARNING:gnupg:FAILURE status emitted from gpg process: decrypt 4294967295. And the&amp;nbsp;decrypted_data is empty.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jul 2025 16:50:50 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/pgp-decryption-in-python-file/m-p/124684#M47242</guid>
      <dc:creator>TetianaDromova</dc:creator>
      <dc:date>2025-07-09T16:50:50Z</dc:date>
    </item>
    <item>
      <title>Re: PGP decryption in python file</title>
      <link>https://community.databricks.com/t5/data-engineering/pgp-decryption-in-python-file/m-p/132887#M49665</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/174442"&gt;@TetianaDromova&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for reaching out and waiting for a response.&lt;/P&gt;
&lt;P&gt;Having your code working on a notebook is a significant first step, so you are on the right path, but then moving into a Python file, we must consider specific details:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;How is this Python code/file being executed? In a Lakeflow Job as a task?&lt;/LI&gt;
&lt;LI&gt;If it is in a Job, what &lt;A href="https://docs.databricks.com/aws/en/jobs/privileges#job-privileges-and-the-run-as-user" target="_self"&gt;user/service principal is configured&lt;/A&gt; to execute this job and task of your Python Code?
&lt;OL&gt;
&lt;LI&gt;&lt;SPAN&gt;When you run code in a notebook, it uses your own credentials, which likely have all the required permissions. However, when running as a Job, the code may run under a different user or principal. You must ensure that this Job principal has the necessary permissions to access your volume in order to read the encrypted file.&amp;nbsp;The same requirement applies to&lt;/SPAN&gt; the &lt;A href="https://docs.databricks.com/aws/en/security/secrets/#manage-secret-scope-permissions" target="_self"&gt;access to the scope and secrets&lt;/A&gt;.&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;Are you using the same cluster with the same libraries installed to execute your notebook and Python files for consistency?&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Based on the error provided, the issue likely occurs when accessing the volume or the secrets, which prevents proper decryption.&lt;/P&gt;
&lt;P&gt;I hope this helps!&lt;/P&gt;</description>
      <pubDate>Wed, 24 Sep 2025 00:17:36 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/pgp-decryption-in-python-file/m-p/132887#M49665</guid>
      <dc:creator>mmayorga</dc:creator>
      <dc:date>2025-09-24T00:17:36Z</dc:date>
    </item>
  </channel>
</rss>

