Rectangle 27 16

the device token is different for dev and prod (for the same device)

I was using the device token I got when testing in dev to test in prod. This was working fine in dev, but when I switched to prod I kept the same device token in my python script (assuming, wrongfully, that the device token would be the same for the same device) but the actual device token registered in prod was different.

In practice this wouldn't happen as the device token is sent to the server, but when I was testing I was using hard coded device token as I didn't want to involve the server.

But I haven't touch production cert yet. How could I even mess with it? Thanks for the quick reply!

This is absolutely correct! The device token in production mode is different from the one in development mode. I've been banging my head for hours trying to figure out what was wrong, & this solved it. Thank you!

This answer just solved a headache i had between client issue's and me personally testing for quite some time. Simply couldn't pinpoint the issue. I take my hat of to u sir! Thanks a bunch. p.s. My problem even took me to changing the .pem files used by the backend for the prod/dev environment.

iphone - Apple Push Notification is not delivered - Stack Overflow

iphone objective-c ios ipad push-notification
Rectangle 27 1

I tested zeep library but got limitations around tokens, by now just support UsernameToken, i report a bug to create timestamp token and author update the code to fix it.

We have TGWS, soaplib (pysimplesoap not tested) IMHO use and help soaplib must be the choice.

Is there good documentation/samples for Suds-jurko? in the repo there are a few .rst files but not much in a way of documentation of how to use the library.

What SOAP client libraries exist for Python, and where is the document...

python soap soap-client
Rectangle 27 0

The issue is that {% block "content" %} should be {% block content %} - the block's name should not be quoted.

{% block content %}{% endblock %}

python - jinja: TemplateSyntaxError: expected token 'name', got 'strin...

python flask jinja2 jinja
Rectangle 27 0

Have you also got the standard Django Templating system installed? That will be required for most apps that are distributed with templates.

For CSRF, a context processor inserts the variable 'csrf_token' into the response context that it retrieves from the middleware if enabled. Now all you have to do, is make sure that it's apart of your form.

if csrf_token:
            if csrf_token == 'NOTPROVIDED':
                return mark_safe(u"")
                return mark_safe(u"<div style='display:none'><input type='hidden' name='csrfmiddlewaretoken' value='%s' /></div>" % csrf_token)

However, seeing that, all you really need to know is that you have to have an input type named csrfmiddlewaretoken with the value of context.get('csrf_token','') within your form and that's all she wrote.

I am having the same problem, What's happening if I don't see the input type named csrfmiddlewaretoken when I look at the source of the template?

@juanky, the point is it must be included in your templates. django provides a {% csrf_token %} context processor for this purpose. If you're using a different templating language, you need to ensure that the html in the code above is included in each and every form within your templates.

I have {% csrf_token %} inside every form, my views use RequestContext instead of request and the TEMPLATE_CONTEXT_PROCESSORS are ordered correctly in but I still get this stupid 'CSRF token missing or incorrect' message

python - Persistent "CSRF token missing or incorrect.". Jinja and djan...

python django csrf
Rectangle 27 0

Angular has a problem with the json parse with unicode.

No, the problem is that the service literally returns

{u'kind': u'bigquery#queryResponse', ...}`.

Which is not JSON. That u right after the { is invalid (which is what the error tells you). Simple proof:

> JSON.parse("{u'foo': 'bar'}");
Uncaught SyntaxError: Unexpected token u

Whatever you do, you are not creating the response properly. Use json.dumps.

Given the fact that the linked tutorial claims the response is JSON is an indicator that it may not be a good tutorial.

However, if you continue to follow the tutorial, you will see that the return proper JSON in the third part.

I tried to consume the data in the tutorial I was reading. Should have looked ahead to see that they modified the output to be JSON. Wondered if there was some "magic" parser in angular js, but thanks for stating there isn't.

How to parse JSON from python service with unicode? SyntaxError: Unexp...

python json angularjs unicode google-bigquery
Rectangle 27 0

I got it working and this is how I did it. Like suggested by toto_tico I worte a dummy view that I retrieve thought GET to get the CSRF token. At first it didn't send the csrf token over GET so I had to add the decorator ensure_csrf_cookie.

def dummy(request):
    return HttpResponse("done")
def my_login(request):
    ...handle login...

It turned out that just adding the cookie to the POST wasn't enough, I had to write a token to the POST data as well.

def _helper(self, url, method="POST"):
    req = urllib2.Request(host + url)
        if method == "GET":
            response =
            for cookie in self.cookieMgr:
                if == "csrftoken":
                    csrf = cookie.value
            values = { "csrfmiddlewaretoken" : csrf}
            params = urllib.urlencode(values)
            response =, params)
            code = response.getcode()
            info =
            content =
            return code, info, content
    except urllib2.HTTPError as ex:
        print str(ex)

def get_csrf(self):
    url = "/license/dummy"
    self._helper(url, method="GET")

def login(self, username, password):
    url = "/license/login?username=%s&password=%s" % (username, password)
    code, info, content = self._helper(url)
    if code == 200:

python 2.7 - Handling CSRF tokens in Django - Stack Overflow

django python-2.7
Rectangle 27 0

In the following line, the code is missing an operand for not in operator.

{% if ?? not in session.logged_in %}

Or, you maybe mean not operator:

{% if not session.logged_in %}

I indeed meant the not operator. I totally read over the in coming after that. I guess it was just a stupid habit doing typing thw in after the not. Thanks a million!

python - How to endif in Flask Jinja2 templating engine. Getting Templ...

python flask jinja2 templating-engine
Rectangle 27 0

In XML, you should encode your ampersands, since they have special meaning.


python - Genshi: TemplateSyntaxError: not well-formed (invalid token) ...

python pylons genshi
Rectangle 27 0

in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/Users/olegmelnik/Desktop/ldid', '-S', '/Users/olegmelnik/Desktop/']' returned non-zero exit status 1

This is what check_call does. If you don't want that, don't use check_call. See the subprocess documentation for more information.

python - syntax error near unexpected token `check_call' . Syntax erro...

python osx terminal
Rectangle 27 0

The error is because the decorator does not expect any arguments (besides the function it is decorating).

def api_important_info():

The configuration values SECURITY_TOKEN_AUTHENTICATION_KEY or SECURITY_TOKEN_AUTHENTICATION_HEADER represent the location in the query params or headers, respectively, of an incoming request.

Flask-Security automatically sends this token to the client for future use when a JSON request is made to the login route.

You may be confused by the multiple authentication methods that Flask-Security provides. Auth tokens are useful for apis where you don't have a session cookie managed by the browser. The "normal" session based authentication is handled with login_required.

Okay, so I've totally misunderstood how to log people in. As you can see I've created a login_view myself which generates and returns a token using get_auth_token(). Would you have a tip on how I could use the views of flask_security? Am I missing something, or is this totally not in the documentation of Flask_Security?

@kramer65 auth tokens are used for apis, such as when making requests outside a browser. You probably want login_required instead, which is the "normal" cookie/session based authentication.

I am actually building an API for an app, so I do need token based authentication. It would really help me if you could give me some tips on how I should actually use the views of flask_security to build a login view and a regular data view for an API..

python - How to get auth_token_required in Flask_Security working? - S...

python flask token peewee flask-security
Rectangle 27 0

<div class="delete-file"><a href="{{ url_for('.delete_file', file_name={{ file.filename }} ) }}">Delete File</a></div><br>

You cannot call a function directly from django template like above. Write custom template tags to satify your purpose.

You mention django, but the question is tagged "flask"

previously it wasn't tagged with flask, the questioner must have updated later..

python - TemplateSyntaxError: expected token ':', got '}' - Stack Over...

python flask
Rectangle 27 0

This is because when Java created the token it thought the plain text you used as a secret was base64 encoded. I am assuming Java was expecting the string secret to be base64 encoded version of some binary. Try base64 decoding the secret before decoding jwt.

import base64

#The token in your question was expired so I ended up passing verify expiration = False
jwt.decode(token,base64.b64decode(secret), options={ 'verify_exp': False})

{u'iat': 1494858980, u'exp': 1494864980, u'sub': u'100', u'roles': u'BUSINESSUSER', u'mode': u'storeapp'}

It worked like a breeze! Thanks. The java jjwt package do not clearly mentions that the secret key we provide is assumed to be a base64 encoded string.

Glad to help, if this answer solved your problem please mark it as accepted by clicking the check mark next to the answer. see: for more information

decode - Convert JWT token created by Java JWT in python - Stack Overf...

jwt decode jjwt pyjwt
Rectangle 27 0

The error message Syntax Error near unexpected token('` is a bash error, not a Python one. You appear to be typing this code into the bash shell rather than into Python.

Yes i am actually accessing this on a shell, do you have any suggestions? what is the best way to run a script of python into a live server. I am using web2py python framework and turnkey linux as server.

If you want to type in Python code directly, you need to do it from within Python, not from bash. You can start Python by typing python. I have no idea what web2py has to do with this, nor what "run a script into a live server" means.

Or what is the best way to implement python on a server

If you're using web2py, you should follow its documentation on deploying it to a server, which appears to be here.

thanks a lot, it really a big help

Syntax Error near unexpected token `(' in alchemyAPI python sdk - Stac...

python alchemyapi
Rectangle 27 0

The problem was due to Flask's jsonify allowing the serialization of NaN, but Google Chrome's implementation following the JSON spec and not allowing NaN.

python - Javascript JSON.parse: Uncaught SyntaxError: Unexpected token...

javascript python json flask
Rectangle 27 0

I updated the question with the place at which i am getting error

python - jQuery file upload with django - getting unexpected token err...

jquery python django
Rectangle 27 0

os.system executes an argument in a subshell, where braces have special meanings. You should use subprocess instead.

But the immediate error is caused by the quotes in

target = "target_dir + os.sep + time.strftime('%Y%m%d') + platform.node() + '.zip'"

This line should almost certainly be

target = target_dir + os.sep + time.strftime('%Y%m%d') + platform.node() + '.zip'

Cheers! Thanks for helping a newb out. Hopefully I can return the favor to someone soon!

using python 2.7 : sh: -c: line 0: syntax error near unexpected token ...

Rectangle 27 0

For starters, the "target = ..." line should probably not be quoted.

using python 2.7 : sh: -c: line 0: syntax error near unexpected token ...

Rectangle 27 0

done is a bash keyword, so can't be used in certain places like "the place Bash expects a command name". You could use ./done (or /path/to/done, or python /path/to/done), or re-name the command.

Very nice! If I rename the script to "cow" it works perfectly... now to find a verb that means complete...


command line arguments - Python: -bash: syntax error near unexpected t...

python command-line-arguments
Rectangle 27 0

  • First I got my access token using python social auth through django (this is well documented) with with manage_pages and publish_actions.

This worked for a while, then stopped working. I found issues with Automated facebook posts not working when the post occurs through Nginx. If I set a delay and ran the post through celery instead the post worked and was scraped.

Python social auth in django to post URL to my business Facebook page ...

python django facebook access-token python-social-auth