giswqs / geemap-heroku

Python scripts for deploying Earth Engine Apps to heroku
MIT License
25 stars 40 forks source link

python config_vars.py error #1

Closed gaowudao closed 4 years ago

gaowudao commented 4 years ago

I followed the steps to run the example. When excute the python config_vars.py, the error occured as follow:

Command '['heroku', 'config:set', 'EARTHENGINE_TOKEN="**]' returned non-zero exit status 1.

giswqs commented 4 years ago

Do NOT post your Earth Engine token publicly!! This is a huge security risk. Anyone can use your token to access your GEE account. If the script does not work for you, you can retrieve the token from your computer and define it on your heroku app.

https://dashboard.heroku.com/apps

gaowudao commented 4 years ago

wow, Thank you very much and your suggestion. I will try.

Ojaybee commented 4 years ago

This line in config_vars.py is throwing an error for me: check_call(['heroku', 'config:set', secret], stdout=DEVNULL, stderr=STDOUT)

I'm on windows 10 and the error message is: [WinError 2] The system cannot find the file specified

Checking the 'token' the slice is incorrect for the windows file. It should be: token = content.split(':')[1][2:-2] to include all characters excluding double quotation marks. The check_call will still throw an exception at this point.

Adding 'shell=True' to the check_call will work on windows (although this might be a security risk?) check_call(['heroku', 'config:set', secret], stdout=DEVNULL, stderr=STDOUT, shell=True)

Setting the variable manually in Heroku does work.

Ojaybee commented 4 years ago

Full working code for Windows 10:

import os
from subprocess import DEVNULL, STDOUT, check_call

def set_heroku_vars(token_name='EARTHENGINE_TOKEN'):
    """Extracts Earth Engine token from the local computer and sets it as an environment variable on heroku.

    Args:
        token_name (str, optional): Name of the Earth Engine token. Defaults to 'EARTHENGINE_TOKEN'.
    """
    try:

        ee_token_dir = os.path.expanduser("~/.config/earthengine/")
        ee_token_file = os.path.join(ee_token_dir, 'credentials')

        if not os.path.exists(ee_token_file):
            print('The credentials file does not exist.')
        else:
            with open(ee_token_file) as f:
                content = f.read()
                token = content.split(':')[1][2:-2]
                secret = '{}={}'.format(token_name, token)
                check_call(['heroku', 'config:set', secret], stdout=DEVNULL, stderr=STDOUT, shell=True)

    except Exception as e:
        print(e)
        return

if __name__ == '__main__':

    set_heroku_vars(token_name='EARTHENGINE_TOKEN')
giswqs commented 4 years ago

@Ojaybee Thank you very much for taking the time to debug the code and provide a working example. I did not realize that the credentials file on Linux is different from the one on Windows/macOS, which has an extra space in it. Therefore, the token slicing on Linux should be different from Windows/macOS. I have incorporated your solution and the config file now seems to run successfully on both Linux and Windows. Thanks.

vijaygrg27 commented 3 years ago

Earth Engine App To authorize access needed by Earth Engine, open the following URL in a web browser and follow the instructions:

https://accounts.google.com/o/oauth2/auth?client_id=517222506229-vsmmajv00ul0bs7p89v5m89qs8eb9359.apps.googleusercontent.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fearthengine+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdevstorage.full_control&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&code_challenge=icCL3HWwyMuza0Geh0R6NakNWylwMKLy-ElLlU2TO8M&code_challenge_method=S256

The authorization workflow will generate a code, which you should paste in the box below

I have added the key in Heroku config_vars but I am getting this error.

giswqs commented 3 years ago

Use the following in your notebook before doing anything with ee. Otherwise, the authentication will fail.

import geemap Map = geemap.Map()

vijaygrg27 commented 3 years ago

I am trying your examples. I have committed your code in my repo but I am not able to deploy it through my github repo. I have deployed the examples with your repo. It's giving problem in my repo my repo https://myfarm12.herokuapp.com/ is not working your repo https://powerful-retreat-90626.herokuapp.com/ is wroking fine

giswqs commented 3 years ago

That mean your EE token was not set properly. Login to heroku to set the token manually. See https://github.com/giswqs/geemap-heroku/issues/1#issuecomment-656101951

vijaygrg27 commented 3 years ago

I am able to do so .It's working fine.I want to update my live location on map.Can you please provide me any source code for Geemap.

Thanks for your quick response

giswqs commented 3 years ago

What do you mean by 'live location'?

vijaygrg27 commented 3 years ago

I want to update the live location on map like Google maps.

giswqs commented 3 years ago

I just implemented this feature. Update the package using geemap.update_package() and then use the following example to zoom to the map to the current device location.

import geemap
Map = geemap.Map()
Map.zoom_to_me(zoom=14, add_marker=True)
Map
vijaygrg27 commented 3 years ago

Thanks I will check and get back to you

vijaygrg27 commented 3 years ago

Location is not correct. I also want track my location on map like Google map

giswqs commented 3 years ago

Try the example below. If it does not give you the correct location, then it is the problem of geocoder, not geemap.

import geocoder

g = geocoder.ip("me")
props = g.geojson["features"][0]["properties"]
lat = props["lat"]
lon = props["lng"]
print(lat, lon)
vijaygrg27 commented 3 years ago

https://openlayers.org/workshop/en/mobile/compass.html Please check this documentation

vijaygrg27 commented 3 years ago

I will try to run this code on mobile. I think It's not working due to laptop.

giswqs commented 3 years ago

geemap is not designed for mobile use. It is not a GPS application. It does not use OpenLayers. geemap will not support getting live locations.

vijaygrg27 commented 3 years ago

How to do it? I am making my project using your Geemap library only. Please guide me

vijaygrg27 commented 3 years ago

I have done everything but my last part is to update the live location on map

giswqs commented 3 years ago

I already told you. geemap does not support getting live locations. Period.

vijaygrg27 commented 3 years ago

Ok 😔

vijaygrg27 commented 3 years ago

Can you please tell me how to calculate the NDVI using planetscope imagery? I want to draw NDVI time series from planet scope imagery.

vijaygrg27 commented 3 years ago

Hi Dr. Qiusheng Wu

I have deployed my application on heroku. Now I want to deploy my application on AWS.I am not able to set config_var.py file for AWS.

Can you please share any reference to deploy the project on AWS. Thanks

giswqs commented 3 years ago

I have not deployed geemap on AWS before. You are welcome to explore it and provide the solution here if you figure it out.

vijaygrg27 commented 3 years ago

I m getting problem to deploy EARTHENGINE_TOKEN in AWS

vijaygrg27 commented 3 years ago

I can't put geemap key on github due to security reason.