DEV Community

TaqsBlaze
TaqsBlaze

Posted on

Using network printer with python

Hi guys so today I've decided to share my experience as I'm currently working on system

so I'm working on a system for centralizing data for an organization
so I got in and these guys didn't have any system or IT systems and I was tasked to build a system from the ground up

So I had to rename their machines for easy access across the network as default windows machine names are random something like DESKTOP-092N4

So after renaming this doesn't register across the network specially when printer drivers where installed before... so my program had to print using this network printer and it took me almost a week to get this working

Not that my code was wrong maybe that's why it took me so long to fix it... I thought the problem was code so my research was centered on code and everything was ok

So I then came across a snippet on the internet thankfully this was a bit detailed with comments as to what's going on
then something got my attention in this code a comment which described a step which wasn't in most examples and something that didn't cross my mind

in this particular snippet it explained setting a default printer win32print.SetDefaultPrinter("printer") so I then implemented this line in my code and finally I was able to use the printer on a network
Originally I was just setting a printer win32print.SetPrinter()
but this caused RPC error whenever I tried printing

Here is why I think it wasn't working:

Though I set the printer using new network path to the printer
\\server\printer this wasn't being used when initiating a print job... it would then use the old network path which is invalid now since I renamed the main PC connected to the printer
so the solution was to just set the default printer using new network path

Top comments (0)