0

I have a practice project given to me by an advisor that asks me to write a python script to access a model I trained with the Prediction API using the API Explorer. I have two questions regarding this,

  1. The guidelines specify that I should not check in my credentials in the Python script and I am not exactly sure what that means, it also leads to question...

  2. When I follow the documentation to call the "predict" method of "trainedmodels" (to predict the language of a text using a trained model)

    from apiclient import discovery
    
    service = discovery.build('prediction','v1.6')
    x = service.trainedmodels().predict(project='My First Project', 
         id='my_project_id', 
         body={"input":{"csvInstance":['bonjour!']}})
    

This is the return value

    <googleapiclient.http.HttpRequest object at 0x1031996d0>

Because I am not too aware of what is meant by "not checking in my credentials", I am unclear as to how to proceed in resolving this problem.

Thank you in advance.

mvkmvk
  • 1
  • 1
  • I might be able to help with the first question. You usually need to provide your credentials to access an API, that's what I do when accessing Twitter API. I'm assuming he's asking you not to include the credentials in your python script, which I'm not sure why since that's the only way to access it properly. Does that sound right? – Leb Jun 10 '15 at 15:18
  • @Leb is it possible the advisor is saying not to hand in a script that still contains their credentials as that is private information? – SuperBiasedMan Jun 10 '15 at 15:20
  • Yes, absolutely. If you provide your credentials you're allowing anyone that can view them to be able to use your information (i.e. username/password). Now there is no sensitive information in that, but the issue lies where they can use them and interfere with your project. – Leb Jun 10 '15 at 15:22
  • if it does not contain the credentials, then wouldn't it not work? i've never used the OAuth standard but i am assuming that is what i need to do, correct? – mvkmvk Jun 10 '15 at 15:25
  • do they mean that i write the script, make sure it works, and then replace my credentials with place-holder strings? – mvkmvk Jun 10 '15 at 15:26

1 Answers1

0

There are at least ways to achieve that:

  • Using the gcloud tool to store your credentials locally (https://cloud.google.com/sdk/gcloud/#gcloud.auth). Those will be easily accessible from within your Python app like below.
  • Creating a configuration file and retrieve the credentials from there

Here's a snippet showing how to access the credentials from within Python:

http = AppAssertionCredentials('https://www.googleapis.com/auth/prediction https://www.googleapis.com/auth/devstorage.read_only').authorize(httplib2.Http())
service = build('prediction', 'v1.6', http=http)
Alexander Graebe
  • 797
  • 5
  • 10