mercredi 12 juillet 2017

CSRF ( or RESTapi) not working while posting data python and laravel

I have created a simple laravel app and deployed it on heroku.

On following link I'm retrieving all events: http://ift.tt/2te7KRu from Cleardb.

On following link: http://ift.tt/2tIeDxW , I'm creating a new event. And everything is working perfect. Still, I want to get and post events through python app on a client (app is not on a server).

Reference for combining python and laravel was the following link

  1. After SO-ing and researching everything I need to ask is there any way to do this and how ?

My python code is following:

import requests

with requests.session() as client:
URL = 'http://ift.tt/2tIeDxW'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'}
responseGet = client.get(URL) 
if(responseGet.status_code ==200):
    csrftoken=client.cookies['XSRF-TOKEN'] # Another token: laravel_session
    myevents =dict(_token=csrftoken,typePy="Conference",placePy="Berlin",dateeventPy="2017-07-11") #_token=csrftoken
    client.post(URL, data=myevents, headers=headers)

After inspecting the page network there is no CSRF token (instead there is XSRF regarding to sample code from link , altough I have set the csrf_field in a view (input name = _token)).

With the python code in the attachment I can GET the data if I change:

URL = 'http://ift.tt/2te7KRu'

But I cannot POST the data.

  1. If this is problem with server configuration, can you explain me what should I configure on a server ?

I'm suspecting that this is a problem with python code but I'm newbie with both python and laravel.

  1. If there is wrong POST code in python, please show me how to configure.

  2. Please show me procedure for handling this problem.

Regards.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2u9ntWK
via IFTTT

Aucun commentaire:

Enregistrer un commentaire