• FarmerPaco

    This is a repeat of a follow-up in a different thread but since it address the matter of access and manipulation of Google Drive files I am going to cross-post it here:

    Just to follow up on this matter. After struggling with PyDrive in pythonista for a while with resulting errors, I opted to just go ahead and try the Google Drive API.

    There is a super simple tutorial in codelabs:
    https://codelabs.developers.google.com/codelabs/gsuite-apis-intro/#0

    Everything installs nicely and runs well. It even lets you complete the authentication in a separate browser if need be. I did the authentication on my raspberry pi and scped the secrets.jason and since then it works perfectly.

    Just in case anyone wants to access and G suite files, you should know that pip in stash running in python3 nicely installs google-api-python-client and oauth2client in the site-packages-3 (which is all you need for Google Drive API).

    posted in Pythonista read more
  • FarmerPaco

    Just to follow up on this matter. After struggling with PyDrive in pythonista for a while with resulting errors, I often to just go ahead and try the Google Drive API.

    There is a super simple tutorial in codelabs:
    https://codelabs.developers.google.com/codelabs/gsuite-apis-intro/#0

    Everything installs nicely and runs well.It even lets you complete the authentication in a separate browser if need be. I did the authentication on my raspberry pi and scped the secrets.jason and since then it works perfectly.

    Just in case anyone wants to access and G suite files, you should know that pip in stash running in python3 nicely installs google-api-python-client and oauth2client in the site-packages-3 (which is all you need for Google Drive API).

    posted in Pythonista read more
  • FarmerPaco

    @bennr01 just want to confirm that installing PyDrive via pip on raspbian downloads pyasn1 0.4.5

    This is not the same with pip in stash 7.1.

    But I honestly don’t know how much it matters.

    posted in Pythonista read more
  • FarmerPaco

    @bennr01 I am not running 7.2. Running 7.1 and that might be part of my problem. Will update shortly.

    Regarding pyasn1, versions 2.1 to 4.2 were released in 2017.

    I believe I am looking at the version of pyasn1 correctly. I only did so because in the original guide I was following @JonB specifically installed a version of pyasn1 after PyDrive. I wanted to make sure my version was the same or higher.

    I looked in: /site-packages-2/pyasn1/init.py

    version = '0.2.1'

    Then I looked in: /site-packages-3/pyasn1/init.py

    version = '0.1.7'

    Not sure why these would be different, or why the version in my python3 would be an earlier version. I am thinking to delete these packages from PyDrive and dependencies, update stash and then reinstall with pip.

    Also plan to do a PyDrive on my raspberry pi today and compare the files.
    I am still new to this stuff but what to understand better what’s happening under the hood.

    posted in Pythonista read more
  • FarmerPaco

    @JonB Thanks again for your time
    I’m going to install PyDrive on my Pi zero to familiarize myself with the normal process so I can debug where along the process my pythonista install is failing.

    I did check the site packages and saw the Stash running 2.7 installs a more updated version of pyasn1 (v. 2.1) where as stash runing at 3.6 installs an earlier version of pyasn1 (v.1.7). This seemed strange.

    Thanks again for your feedback. I will finish a PyDrive install on Rasbian (debian) which should be straightforward and then see where I am going wrong on Pythonista.
    I will also check stash/bin/scp.py

    posted in Pythonista read more
  • FarmerPaco

    @JonB thanks for pointing out my options. Will probably try installing the ssh python module first.
    Normally when I think of ssh I think of Bash, and since Stash (from what I read) is really just emulating a shell, I wasn’t sure if that would get in the way.
    I guess there is only one way to find out.
    Again, thanks.

    posted in Pythonista read more
  • FarmerPaco

    @mikael thanks for this. I will check it out later, but it looks like something I should know.
    I am assuming that in s.connect the port is 22 for sftp.
    Thanks for the pointer.

    posted in Pythonista read more
  • FarmerPaco

    @JonB Yes, it is. I use scp in stash, but was hoping to be able to call scp from inside a python3 script.
    Something like this:

    from paramiko import SSHClient
    from scp import SCPClient
    
    ssh = SSHClient()
    ssh.load_system_host_keys()
    ssh.connect('example.com')
    
    with SCPClient(ssh.get_transport()) as scp:
        scp.put('test.txt', 'test2.txt')
        scp.get('test2.txt')
    

    I know there is an scp python module:
    python scp module

    Can I call a Stash command from a python3 file to run scp from stash?
    Sorry if I am not making sense.
    Thank you again, since I feel like I keep asking you questions.

    posted in Pythonista read more
  • FarmerPaco

    @JonB thanks again for coming to the rescue (I remember you helped me with turtle2).

    Let me indicate what I did:

    1.installed PyDrive with Stash running in 2.7 which installed to Site packages 2. I realized this when I tried to run the following code in python 3.6

    from pydrive.auth import GoogleAuth
    from pydrive.drive import GoogleDrive
    import webbrowser
    
    # Create local webserver and auto handles authentication.
    # Standard webbrowser gave an error, JonB found the solution
    if not hasattr(webbrowser,'_open'):
        webbrowser._open=webbrowser.open
    def wbopen(url, *args,**kwargs):
        return webbrowser._open(url)
    webbrowser.open=wbopen
    
    gauth = GoogleAuth()
    gauth.LocalWebserverAuth()
    
    # upload 
    drive = GoogleDrive(gauth)
    
    file1 = drive.CreateFile({'title': 'Hello.txt'})  # Create GoogleDriveFile instance with title 'Hello.txt'.
    file1.SetContentString('Hello World!') # Set content of the file from given string.
    file1.Upload()
    
    file1 = drive.CreateFile({'title': 'pyconnect.py'})  # Create GoogleDriveFile instance with title ...
    file1.SetContentFile('pyconnect.py') # Set content of the file from given file
    file1.Upload()
    

    and received an import error.

    1. Installed PyDrive again in stash running python 3.6. Now I have the PyDrive module in both site packages.

    Tried to run code and received an error in line 202 of the discovery.py dependency.
    I need to admit that I have not done a pip install of pyasn1 because the printout on the PyDrive install stated that the dependency was already there.

    I appreciate your help.
    Since I have PyDrive installed in both site packages. My questions are:

    1.Do I still need to reinstall pyasn1 like you did originally?

    1. @cvp is running PyDrive in python3. Can PyDrive by installed using stash running 3.6? I plan to use PyDrive in python3 exclusively. I use this for education. (Full disclosure: I am a lousy teacher and an even worse student).

    2. Why would I get a syntax error in discovery.py (which I am not even sure what it is.) Can I reinstall this modul again without errors from pip install?

    @shinyformica thanks for the offer for help. I will probably take you on it was I reach the authentication stage. I have already complete my google console step, downloaded the unknown file, remained and move to my current directory.

    Thank you everyone for taking time from your surely busy schedules to help me.
    Thank yo in advance for any further guidance.
    I want to install PyDrive on pythonista on my students so they can automate checking their work.

    Best,
    Justin

    posted in Pythonista read more
  • FarmerPaco

    Hi @JonB and @cvp
    Just completed this install.

    Run with python3
    Returns syntax error on line 202 of discovery.py

    Traceback reads:

    Traceback (most recent call last):
    File "/private/var/mobile/Containers/Shared/AppGroup/BDD90EB4-7B3E-4A50-A939-642531B58BFE/Pythonista3/Documents/pyconnect.py", line 1, in <module>
    from pydrive.auth import GoogleAuth
    File "/private/var/mobile/Containers/Shared/AppGroup/BDD90EB4-7B3E-4A50-A939-642531B58BFE/Pythonista3/Documents/site-packages-3/pydrive/auth.py", line 7, in <module>
    from apiclient.discovery import build
    File "/private/var/mobile/Containers/Shared/AppGroup/BDD90EB4-7B3E-4A50-A939-642531B58BFE/Pythonista3/Documents/site-packages-3/apiclient/discovery.py", line 202
    except ValueError, e:
    ^
    SyntaxError: invalid syntax

    Does PyDrive still work with pythonista?

    (With python2.7 I also get a name error: cannot import name util )

    Any pointers or help would be much appreciated.
    Thanks in advance

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!