Friday, July 29, 2022

[SOLVED] Paramiko ValueError "p must be exactly 1024, 2048, or 3072 bits long"

Issue

I am trying to connect SFTP using Python script. I'm unable to connect due to "p error".

import paramiko
client = paramiko.SSHClient()
client.load_system_host_keys()
client.connect('####.com', username='####', password='###')
stdin, stdout, stderr = client.exec_command('ls -l')

Error:

ValueError: p must be exactly 1024, 2048, or 3072 bits long


Solution

Find the value of p and include calculated p in dsa.py file and save it.

how to calculate P:

def _check_dsa_parameters(parameters):

    print(parameters.p.bit_length(),"value of p")
    if parameters.p.bit_length() not in [1024, 2048, 3024]:

include p in this list:

(if parameters.p.bit_length() not in [1024, 2048, p-value]:)

After modification:

def _check_dsa_parameters(parameters):

    if parameters.p.bit_length() not in [1024, 2048, p-value]:
        raise ValueError("p must be exactly 1024, 2048, or 3072 bits long")

Post to rectification it worked Fine. Thanks



Answered By - manuzz
Answer Checked By - Terry (WPSolving Volunteer)