Jump to content
Ultimaker Community of 3D Printing Experts

Ultimaker S5 API authentication problem


Recommended Posts

Posted · Ultimaker S5 API authentication problem

Hello,

I have a question about the rest API,

When I try to authenticate using a key and id I got from /auth/request,

It always returns the 401 authentication required, no matter where I enter it on postman.

does anyone know what I am doing wrong?

thanks in advance!

  • Link to post
    Share on other sites
    Posted · Ultimaker S5 API authentication problem
    Quote

    I learned here that Postman and the firmware do not speak the same dialect of "http digest" somehow...

    But the python script works like a charm

    I tried that, but I get a missing argument error on the api.loadauth subroutine, cus the "auth.data" is going in to self, and the filename is not specified, if I add that it doesn't work either, I am using python 3.7.5

  • Link to post
    Share on other sites
    Posted · Ultimaker S5 API authentication problem

    not my field of expertise, i copied some lines from several places a while ago. 🤷‍♂️

    Windows and Python 3.5.2 in my case. I changed the initAPI function to this:

     

    # ...
    	# dunno, if this has changed too?
        def loadAuth(self, filename):
            try:
                data = json.load(open(filename, "rt"))
                self.__setAuthData(data["id"], data["key"])
            except IOError:
                self.__checkAuth()
                self.saveAuth(filename)
            self.__checkAuth()
    
    # ...
    
    # always load data file from module directory
    def initAPI(ip):
        # script name
        filename = os.path.realpath(__file__)
        sname = os.path.basename(filename)
        datafile = os.path.splitext(filename)[0] + ".data"
    
        # authenticate      
        api = Ultimaker3(ip, sname)
        api.loadAuth(datafile)
        
        return api

     

  • Link to post
    Share on other sites
    Posted · Ultimaker S5 API authentication problem
    7 hours ago, tinkergnome said:

    a complete working example was uploaded here:

     

     

    I have a problem with uploading files to the printer, when I try to, I get the error 400 bad response back.

    anyone know how to fix that?

    UM3_API.zip

  • Link to post
    Share on other sites
    Posted · Ultimaker S5 API authentication problem
    4 hours ago, JurgenMK said:

    I have a problem with uploading files to the printer, when I try to, I get the error 400 bad response back.

    anyone know how to fix that?

     

    I'm not sure, either this (older) network printing doesn't work anymore or we use it in a wrong way?

    I use only the new API for this, i hope it still works in the same way in this new "digital factory" age (my UM3 has not heard yet of those fancy things... 😏)

     

    Have a look at the documentation on the printer.

    http://169.254.168.50/cluster-api/v1/

     

    Something like this (from a windows batch file):

     

    set URL=http://169.254.168.50:80/cluster-api/v1/print_jobs/
    set FILENAME=UM3_UltimakerRobot_support.gcode
    curl -X POST --header "Content-Type: multipart/form-data" --header "Accept: application/json" -F "file=@%FILENAME%" %URL%

     

  • Link to post
    Share on other sites
    Posted · Ultimaker S5 API authentication problem
    14 hours ago, tinkergnome said:

     

    I'm not sure, either this (older) network printing doesn't work anymore or we use it in a wrong way?

    I use only the new API for this, i hope it still works in the same way in this new "digital factory" age (my UM3 has not heard yet of those fancy things... 😏)

     

    Have a look at the documentation on the printer.

    http://169.254.168.50/cluster-api/v1/

     

    Something like this (from a windows batch file):

     

    
    set URL=http://169.254.168.50:80/cluster-api/v1/print_jobs/
    set FILENAME=UM3_UltimakerRobot_support.gcode
    curl -X POST --header "Content-Type: multipart/form-data" --header "Accept: application/json" -F "file=@%FILENAME%" %URL%

    okey that works, but when I try to do the exact same thing in my python code I get a response 200 back, and the print doesn't start.

    
    import UM3_API
    UM3_API.start_print("UM3_UltimakerRobot_support.gcode")
    
    .......
    
    def start_print(file):
        api = initAPI("169.254.113.5")  
        if os.path.exists(file):
            jobname = os.path.basename(file)
            filepath = file
            print(filepath)
            print(api.post("cluster-api/v1/print_jobs", headers={"Content-Type": "multipart/form-data", "Accept": "application/json"}, files={"file": (jobname, open(filepath, "rb"))}))

    what am I doing wrong?

     

  • Link to post
    Share on other sites
    Posted · Ultimaker S5 API authentication problem

    dunno... but i would not use the "api" object at all for this task.

    The cluster-api works different, no authentification, and does not know the "jobname" parameter (AFAIK).

     

    Can't you simply mimic the curl command with a python library or such....?

    https://stackoverflow.com/questions/43246857/python-requests-post-a-file

  • Link to post
    Share on other sites
    Posted · Ultimaker S5 API authentication problem
    2 hours ago, tinkergnome said:

    dunno... but i would not use the "api" object at all for this task.

    The cluster-api works different, no authentification, and does not know the "jobname" parameter (AFAIK).

     

    Can't you simply mimic the curl command with a python library or such....?

    https://stackoverflow.com/questions/43246857/python-requests-post-a-file

    I tried that already, but then I still get the 200 back instead of 201

  • Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    • Our picks

      • Talking additive | The 3D printing podcast
        Why should we be the only ones asking questions? Join us and ask Jabil all your questions on September 22nd 5pm CET
          • Like
        • 3 replies
      • Ultimaker masterclass: Optimizing your Ultimaker Cura workflow
        Save your seat for either broadcast on September 23.
        What will you learn?
        · Best practices for iterative print preparation and every lesson you should learn from each print
        · The right way to use per-object settings and when they are most useful
        · Easy-to-use resources for anyone who wants to develop their own printer definitions, plugins, or print profiles
        · How to optimize print profile settings and whether to “keep” or “discard” changes
        · When is the right time to export your drawing from CAD? (Based on Ultimaker Cura’s surprising power as 3D control software)
        · And a whole lot more tips and tricks!
         
        How can I join?
        This free masterclass will take place twice:
        1. 11am CEST (5pm SGT, 5am EDT)
        2. 5pm CEST (11am EDT, 8am PDT, 11pm SGT)
          • Like
        • 0 replies
      • Do you use 3D printing at work? Let us know
        It doesn't matter if you are using 1 Ultimaker or 10, there is inspiration in everything. We're looking for ...
        • 1 reply
    ×
    ×
    • Create New...