milesrichardson / ParsePy

A relatively up-to-date fork of ParsePy, the Python wrapper for the Parse.com API. Originally maintained by @dgrtwo
MIT License
516 stars 184 forks source link

"Unauthorized" when using ParsePy in Script #144

Closed LaBrie13 closed 8 years ago

LaBrie13 commented 8 years ago

I have a weird issue, which just came up lately without a change in the script. What I will describe can be executed in the python console most of the times, not always. I am using self hosted parse. the code is as follows:

from parse_rest.datatypes import Function, Object, GeoPoint
import os
os.environ["PARSE_API_ROOT"] = "http://server:1337/parse"
APPLICATION_ID = '###'
REST_API_KEY = '###'
MASTER_KEY = '###'
from parse_rest.connection import register
register(APPLICATION_ID, REST_API_KEY, master_key=MASTER_KEY)

id = "1234"
parseClass = Object.factory("Classname")
newObj = parseClass.Query.get(objectId = id)

by executing this I get an error: "ResourceRequestLoginRequired" , unauthorized

any idea? Your help is very much appreciated! :-)

milesrichardson commented 8 years ago

Put

os.environ["PARSE_API_ROOT"] = "http://server:1337/parse"

at the top of the script, BEFORE you make any imports from parse_rest

You should also put the keys before the imports

The proper order is here: https://github.com/milesrichardson/ParsePy#using-with-self-hosted-parse-server

so the full script would be:

import os
os.environ["PARSE_API_ROOT"] = "http://server:1337/parse"    
APPLICATION_ID = '###'
REST_API_KEY = '###'
MASTER_KEY = '###'

from parse_rest.datatypes import Function, Object, GeoPoint
from parse_rest.connection import register
register(APPLICATION_ID, REST_API_KEY, master_key=MASTER_KEY)

id = "1234"
parseClass = Object.factory("Classname")
newObj = parseClass.Query.get(objectId = id)

Let me know if that fixes it

LaBrie13 commented 8 years ago

Thanks a lot for your quick response! So simple, but it really saved me! :+1:

milesrichardson commented 8 years ago

no problem :)