[Python] Not able to access file server using smbprotocol python library

Discussão em 'Python' iniciado por Stack, Maio 23, 2025.

  1. Stack

    Stack Membro Participativo

    We have written a script deployed on Azure function which performs some operation on data stored in file server and stores the processed data back to file server. This script was working fine for last 1 month but now suddenly we have encountered below logon error:

    2025-05-22T16:58:28.303Z]

    Initialising connection, guid: 352310-3c3-4b06-ad7-3f33ecfc, require_signing: True, server_name: 10...*, port: 445

    2025-05-22T16:58:28.305Z]

    Setting up transp connection

    2025-05-22T16:58:28.306Z]

    Connecting to DirectTcp socket

    2025-05-22T16:58:28.3472]

    Starting negotiation with SMB server

    2025-05-22T16:58:28.3482]

    Negotiating with SMB2 protocol with highest client dialect of: SMB_3_1_1

    2025-05-22T16:58:28.3492]

    Sending SMB2 Negotiate message

    2025-05-22T16:58:28.3817]

    Receiving SMB2 Negotiate response

    2025-05-22T16:58:28.3822]

    Negotiated dialect: (785) SMB_3_1_1

    2025-05-22T16:58:28.386Z]

    Connection require signing: True

    I

    2025-05-22T16:58:28.388Z]

    Initialising session with username: agsgh**@***.com

    2025-05-22T16:58:28.3902] 2025-05-22T16:58:28.3917]

    Sending SMB2 SESSION SETUP request message

    Receiving SMB2_SESSION_SETUP response message

    2025-05-22T16:58:28.4232]

    More processing is required for SMB2 SESSION_SETUP

    2025-05-22T16:58:28.427Z]

    Sending SMB2 SESSION SETUP request message

    2025-05-22T16:58:28.428Z]

    Receiving SHB2_SESSION SETUP response message

    2025-05-22T16:58:28.5262] Error while saving file to SMB --> Received unexpected status from the server: The attempted logon is invalid. This is either due to a bad username or authentication information . (3221225581) STATUS LOGON FAILURE: 0xc000006d

    Can it be due to firewall or network issue? It is already allowed on port 445. Should it be allowed for other ports too like 139,2049,443?

    I'm using smbprotocol library to connect to file server and below is my python code. Please help me to resolve this issue.

    json_string = data.replace('\n', '')

    fixeddata json.loads(json_string)

    FolderName = self.config.SHARED_FOLDER_PATH_FOR_OUTPUT

    SubFolderName = Fileid

    smb_base_path = f"\\\\10.*.*.*\\{FolderName}\\{SubFolderName}"

    smb_file_path=f"{smb_base_path}\\{contractnumber}.json"

    username "USER"

    password = "PSWD"

    if not smbclient.path.exists(smb_base_path, username=username, password=password):

    logging.info(f"Folder {smb_base_path} does not exist. Creating it...")

    smbclient.makedirs(smb_base_path, username=username, password=password)

    logging.info(f"Folder {smb_base_path} verified or created successfully.")

    with smbclient.open_file(smb_file_path, mode="w", username=username, password=password) as file:

    json.dump(fixeddata, file)

    logging.info(f"File saved to {smb_base_path}")

    Continue reading...

Compartilhe esta Página