last day (15 days later) » 

5:11 PM
4
A: python-requests - user-agent is being overriden

alecxeheaders are not kept inside session this way. You need to either explicitly pass them every time you make a request, or set the s.headers once: with requests.Session() as s: s.headers = {'User-Agent': 'Mozilla/5.0'} You can check that the correct headers were sent via inspecting response...

 
oh ok, didnot know that
so, I did s.post(url, data=json.dumps(logindata), headers={'User-Agent': 'Mozilla/5.0'}) but still getting different headers if I print
you always come with good news :) thank you
 
@doniyor hope both answers here helped to clear things up.
 
the headers is fine now, but i am still getting 403. very weird..
 
@doniyor ok, what response are you getting from s.post() call? what if you omit json.dumps() call: r = s.post(api_url, data=logindata)?
 
from s.post() I am getting 403. I am trying to login into django admin page. am I missing probably csrftoken?
 
5:11 PM
@doniyor most likely this is it. Inspect the POST request going to django admin when you do it manually in the browser. If your theory is right, when you'll see csrfmiddlewaretoken parameter there.
 
yep, that was it. now s.post() is giving 200. but s.get() is still 403 :(
I think, I need to put csrftoken inside sessionobject?
 
hey there
first, check r.cookies where r is the result of the first POST request
 
hey,
ok, so the r the result of loginrequest, right?
 
might be helpful
yup
 
yep. one sec, i will try it
ok, i see the csrf cookie in it
may be i will see into the s.get()'s result if it has the cookie
 
5:15 PM
since it is a session - it should have
btw, why do you need to make a separate GET request here?
 
good question :D
i am giving some urls in get
it should be get
because the other end looks for GET attribute from me
 
hm, okay :)
 
one sec, i will look into it
look, ineresting
print r.cookies
i did this for s.get()
 
mhm
 
and it does not have cookie in it
hence the 403
right?
 
5:18 PM
mm, but what is inside?
cookies
 
only requestCookieJar class
but not the csrftoken Cookie
 
wait!
 
unline s.post
 
it might be about the referer
 
ah
 
5:19 PM
see Martijn's answer here
3
Q: Passing csrftoken with python Requests

JeffHow do you pass a csrftoken with the python module Requests? This is what I have but it's not working, and I'm not sure which parameter to pass it into (data, headers, auth...) import requests from bs4 import BeautifulSoup URL = 'https://portal.bitcasa.com/login' client = requests.session(con...

 
ah, i will test
 
is the site out there on the web so I can test too?
 
sure, but you would need credentials to login in?
 
e.g. if you have test credentials, or I can register?
would be easier, difficult to imagine what is going on, need to see :)
 
yeah absolutely yourright, but i am working companies page, :(
but it is in dev version
may be i can give you
because i trust you yo ;)
#'username': 'quiz-Daniel', # dev
#'password': 'vEhIwc5r'
 
5:25 PM
thanks, what code do you have so far?
 
let me check
yes, I can
I won't look around
don't worry
just test the problem
 
cool, you are my mentor if they ask me who you are ;)
 
:D
please also delete the credentials from the chat
and the url
 
oops
how can i delete ? :)
heck, i cannot delete :(
 
5:30 PM
well this is not a public room at least
but see
 
you can test to pass any get parameters to that page and see if you can
 
2
Q: Is it possible to delete a chat conversation?

GaniI posted some sensitive information, and now I want to delete the chat conversation so it isn't public. Is there way I can remove that information? It's very urgent!

I've removed the link to chat from comments
I think this should be enough
 
yeah perfect
yes
;)
cool
 
okay, back to the code
 
lets worry about code
yes
 
5:32 PM
could you post what are you executing now?
with the new csrf part
 
right here?
with requests.Session() as s:
s.get('http://dev.what-character-are-you.com/admin/') # sets the cookie
csrftoken = s.cookies['csrftoken']

logindata = dict(username='xxxxx', password='xxxx', csrfmiddlewaretoken=csrftoken)

s.headers = {'User-Agent': 'Mozilla/5.0'}
s.post('http://dev.what-character-are-you.com/admin/', data=logindata)


r = s.get(matthias_api, params=payload, headers={'User-Agent': 'Mozilla/5.0'})

print r.cookies
 
good, give me some time to debug
 
yep
 
login and password again :D
in the code
 
oh sheese
:D
 
5:34 PM
but now you have time to remove it
 
done
:)
i think i need something like s.headers = {'User-Agent': 'Mozilla/5.0'}.. but for cookie
I need sessionwide csrf
 
I think I made some progress
auth part
import requests

login_url = 'http://dev.what-character-are-you.com/admin/'
api_url = 'http://dev.what-character-are-you.com/admin/app/import/'

with requests.Session() as s:
s.headers = {'User-Agent': 'Mozilla/5.0'}

s.get(login_url)
csrftoken = s.cookies['csrftoken']

logindata = dict(username='xxx', password='xxx', csrfmiddlewaretoken=csrftoken, this_is_the_login_form='1', next='/admin/')


r = s.post(login_url, data=logindata)

print r.status_code
print r.content
 
auth part was already working right? i mean i got 200 from s.post( )
 
yup, but I've seen the session expired message inside
so it was not working properly I think
 
aaah
may be this can be passed to s.get() now
lemme test
i dont havt to change "this_is_the_login_form" right?
look
now I am getting 500
:)
 
5:51 PM
good!
 
but this is good
yes
this is the other end's error
meaning, i can access now, right?
 
I think so
what is inside the .content
?
 
one sec
 
of the get request's response
probably HTML code, but you can find an error text inside
 
yes it is 500 page
but it is too long for shell, cannot see the top part..
i can dump into txt file right?
 
5:56 PM
yup
or even save as html and open up in the browser
or parse with BeautifulSoup
many options :)
 
yeah
duh
[Errno socket error] [Errno 111] Connection refused
I am sending from 127.0.0.1
i am dumb
i need to save this priceless chat history somewhere
 
connection refused? hm
 
it is because 127.0.0.1
 
also, to be safe, change your password
I'll be AFK for a while, but I'll leave the chat open
 
are you at job right now?
 
6:09 PM
my job is my laptop :)
need to go for a walk with my daughter :)
what about you?
 
i am at work now, finished my study 4 monaths ago, now working fulltime django. thereis nothign better :D
i am 28 and i have 1 year old son
 
yeah, I'm keeping track of several tags and I've been seeing your questions and answers a lot :)
good q&a, btw
1 year old - very interesting age!
 
really?
:D
 
he probably starts to walk on his own, right?
 
yeeah he is already running :D
 
6:13 PM
awesome!
now he can reach easily whatever he wanted before :)
and even things he is not supposed to reach :D
 
yeeeeah
:D
how many kids do you have?
 
just one
for now :)
working on it
:D
 
:D
nice
 
do you have gmail/linkedin?
 
sure.
 
6:16 PM
better continue there I think
 
doniyor.v.j@gmail.com
and skype: doniyor.lmu.doniyor1
keep in touch, i am always available..
 
thanks, sent you a hangout message
and sent a skype request
 
perfect
 
ok let's keep in touch then
gotta go
hope to hear from u soon
 
yes. i will write you :)
bye and have fun
 
6:19 PM
bye!
 
bye
 

last day (15 days later) »