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

Can't get work any methods #168

Closed fuzunspm closed 6 years ago

fuzunspm commented 7 years ago
class className(Object):
    pass

fields = className(name="Joh", surname='Doe')
fields.save()
print(className.Query.all())

I'm getting error of:

    if _is_illegal_header_value(values[i]):
TypeError: expected string or bytes-like object

I can't follow documentation could you please help me to fix it?

dhaneshsabane commented 6 years ago

I have been facing a similar issue with basic queries.

Here's what my function looks like:

def getTaskAppCount(Object):
    myClassName = "EarnNowTaskApplication"
    myClass = Object.factory(myClassName)
    all_scores = myClass.Query.all()
    print(type(all_scores))

    for score in all_scores:
        # do something

    return someValue

The function fails with:

if _is_illegal_header_value(values[i]):
TypeError: expected string or bytes-like object

What am I doing wrong?

milesrichardson commented 6 years ago

Hey guys @Dhanesh95 @fuzunspm

Sorry I've really dropped the ball on this project. I inherited it from the previous maintained because he didn't use it / have time for it anymore, and now I'm in the same position! Embarrassing, I'm sorry.

Since parse-server has been open sourced, there has been a lot of changes to it. It might make sense to start a fresh project targeting latest python3 / asyncio and the latest parse.

That said, I am unable to reproduce these bugs. I tried in both python3 (3.6) and python2. I'm running against parse-server 2.7.1.

Could you please put together a single file that reproduces the bug and paste it here? And let me know exactly which versions of Python and parse-server you are running.

Googling for this "is_illegal_header_value" turns up some other projects having issues with Python 3.5+ related to \n in header values: https://github.com/evernote/evernote-sdk-python3/issues/16 which stems from a fix to https://bugs.python.org/issue22928

But I don't see anywhere in this project that is inserting \n into header values (at least at a quick glance). And as I said I cannot reproduce this bug. Are you sure you are not including a newline somewhere? Perhaps in some of your environment variables used to configure parse?

milesrichardson commented 6 years ago

Are you running on windows?

milesrichardson commented 6 years ago

I tried reproducing this in a bunch of scenarios:

(One thing -- I am running parse_server behind nginx, and not so easy for me to change that in my current setup. Maybe this is the issue, idk.)

Unable to reproduce. Here is the code I'm using:

Logged in user:

import os
os.environ["PARSE_API_ROOT"] = "http://localhost:9595/api/parse"

from parse_rest.datatypes import Function, Object, GeoPoint, File
from parse_rest.connection import register
from parse_rest.query import QueryResourceDoesNotExist
from parse_rest.connection import ParseBatcher
from parse_rest.connection import SessionToken
from parse_rest.core import ResourceRequestBadRequest, ParseError
from parse_rest.user import User

from parse_rest.connection import SessionToken, register

from pprint import pprint

APPLICATION_ID = 'appID'
REST_API_KEY = 'restAPIKey'

register(APPLICATION_ID, REST_API_KEY)

class Fund(Object):
    pass

u = User.login('gary.chalmers@springfield.com', 'test')

print(u.sessionToken)

with SessionToken(u.sessionToken):
    funds = Fund.Query.all()
    for fund in funds:
        print(fund)

    fund2 = Fund(fundName='test name')
    fund2.save()

Master key:

import os
os.environ["PARSE_API_ROOT"] = "http://localhost:9595/api/parse"

from parse_rest.datatypes import Function, Object, GeoPoint, File
from parse_rest.connection import register
from parse_rest.query import QueryResourceDoesNotExist
from parse_rest.connection import ParseBatcher
from parse_rest.connection import SessionToken
from parse_rest.core import ResourceRequestBadRequest, ParseError
from parse_rest.user import User

from parse_rest.connection import SessionToken, register

from pprint import pprint

APPLICATION_ID = 'appID'
REST_API_KEY = 'restAPIKey'
MASTER_KEY = 'masterKey'

register(APPLICATION_ID, REST_API_KEY, master_key=MASTER_KEY)

class Fund(Object):
    pass

funds = Fund.Query.all()
for fund in funds:
    print(fund)

fund2 = Fund(fundName='test name')
fund2.save()
milesrichardson commented 6 years ago

Bunch more info here: https://www.google.com/search?q=%22_is_illegal_header_value%22

dhaneshsabane commented 6 years ago

@milesrichardson Thanks a ton for your quick response!

It works now. Turns out it was an incorrect environment variable. Sorry for the false alarm!

I was extremely happy to find out about this project today and I'm sorry to hear that you have dropped the ball. Thanks a lot for your efforts.

milesrichardson commented 6 years ago

It still works for 99% of use cases as far as I know. I wouldn't be scared to use it. I'm also happy to review any PRs for bugs you encounter. Just don't have time to add new features.