omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    FTP in appex mode

    Pythonista
    4
    14
    6396
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • dgelessus
      dgelessus last edited by

      Why the try/except? When an exception happens, Python will automatically stop the program and display the full error message and traceback, so there's no need for a ftpok variable or a manual console.alert.

      The issue with catching exceptions by hand (especially with a bare except or an except Exception) is that you're hiding Python's information about the error and displaying your own error message instead. This isn't very useful when you're trying to find out what's going wrong.

      1 Reply Last reply Reply Quote 1
      • cvp
        cvp last edited by cvp

        I don't want that my program stops, I want to continue, warn the user there is a problem accessing the Mac, perhaps access of my backup on a NAS etc...

        I'm sure I do something bad, please explain me what is "outside the extension"

        1 Reply Last reply Reply Quote 0
        • cvp
          cvp last edited by cvp

          I've removed my try/except to get the errors info:

          Traceback (most recent call last):
          File "/private/var/mobile/Containers/Shared/AppGroup/BC53E549-355D-4E77-BC46-64C3D3E0BDAF/Documents/MesApps/Epubs.py", line 265, in <module>
          main()
          File "/private/var/mobile/Containers/Shared/AppGroup/BC53E549-355D-4E77-BC46-64C3D3E0BDAF/Documents/MesApps/Epubs.py", line 240, in main
          get_authors()
          File "/private/var/mobile/Containers/Shared/AppGroup/BC53E549-355D-4E77-BC46-64C3D3E0BDAF/Documents/MesApps/Epubs.py", line 65, in get_authors
          ftp.login(user,pwd)
          File "/var/containers/Bundle/Application/46D4F46D-99D6-4950-9EB8-993E92B02425/Pythonista.app/Frameworks/PythonistaKit.framework/pylib/ftplib.py", line 389, in login
          if resp[0] == '3': resp = self.sendcmd('PASS ' + passwd)
          File "/var/containers/Bundle/Application/46D4F46D-99D6-4950-9EB8-993E92B02425/Pythonista.app/Frameworks/PythonistaKit.framework/pylib/ftplib.py", line 245, in sendcmd
          return self.getresp()
          File "/var/containers/Bundle/Application/46D4F46D-99D6-4950-9EB8-993E92B02425/Pythonista.app/Frameworks/PythonistaKit.framework/pylib/ftplib.py", line 220, in getresp
          raise error_perm, resp
          ftplib.error_perm: 530 Login incorrect.

          1 Reply Last reply Reply Quote 0
          • omz
            omz last edited by

            @cvp said:

            I don't understand your question "outside of the app extension"

            What I meant was: Does your script work when you run it in the Pythonista app, and not from the share sheet.

            1 Reply Last reply Reply Quote 0
            • cvp
              cvp last edited by

              Yes, it functions.
              And my little test script functions in the appex mode

              1 Reply Last reply Reply Quote 0
              • omz
                omz last edited by

                Are you using the keychain module to get the password by any chance? The keychains of the app extension and the main app are separate, so that could be the reason...

                1 Reply Last reply Reply Quote 0
                • cvp
                  cvp last edited by cvp

                  I just tried without keychain and discovered that. I was busy to write this text when I received your advice... In French, we say "Les grands esprits se rencontrent" 😀
                  Thanks and sorry for the disturbance

                  1 Reply Last reply Reply Quote 2
                  • ccc
                    ccc last edited by

                    "Les grands esprits se rencontrent" == "Great minds think alike"

                    1 Reply Last reply Reply Quote 4
                    • dgelessus
                      dgelessus last edited by

                      @cvp The traceback is useful, as you see :) It's best to first make sure that your program works correctly in all cases, and then perhaps add more friendly error messages using try/except. And you should almost never use except without an exception name or except Exception - only catch the exception that you want. For example, to display a nice error message when the password is incorrect, use except ftplib.error_perm. Otherwise you'll catch other exceptions by accident that you didn't expect, which makes debugging very hard.

                      1 Reply Last reply Reply Quote 0
                      • cvp
                        cvp last edited by

                        Thanks for your advices
                        It's sure I'll stay a beginner for some time 😉

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        Powered by NodeBB Forums | Contributors