Create New Comment In Xenforo

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
wichit12
User
Beiträge: 4
Registriert: Freitag 19. Dezember 2014, 14:29

Hi,

https://xenforo.com/community/threads/n ... nbsp.3864/

i want to add new comment "thanks" to above topic
It can login but can not reply topic.
Here my code, please help me fix. Thanks a lot

Code: Alles auswählen

import requests 
with requests.session() as c: 
    url='https://xenforo.com/community/login/login' 
    USERNAME='minneconsin@gmail.com' 
    PASSWORD='Demo12345' 
    c.get(url) 
    session=requests.session() 
    login_data=dict(login=USERNAME,password=PASSWORD,next="/") 
    c.post(url,data=login_data,headers={"Referer":"https://xenforo.com/community/"}) 

    thisvalues='Thanks' 
    thisurl='https://xenforo.com/community/threads/nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp.3864/' 

    r=requests.post(thisurl,data=thisvalues) 
    session.close() 
    session.__exit__() 
Sirius3
User
Beiträge: 18335
Registriert: Sonntag 21. Oktober 2012, 17:20

@wichit12: do you get some error message?

Why do you introduce the variable session? It's never used. And you should not call __exit__ directly, that's only used by the with-statement. Your second post request is not done in the same session as the login request. You probably ment `r=c.post(thisurl, data=thisvalues)`. Btw. `c` is no good name for a variable, because the name should mean something, the same with `thisvalues` and `thisurl`; the `this` doesn't add any information to the name.
wichit12
User
Beiträge: 4
Registriert: Freitag 19. Dezember 2014, 14:29

@sirius3

Thanks for your advices. How to fix my code? help me pls
Sirius3
User
Beiträge: 18335
Registriert: Sonntag 21. Oktober 2012, 17:20

@wichit12: read my answer.
wichit12
User
Beiträge: 4
Registriert: Freitag 19. Dezember 2014, 14:29

@sirius3

Code: Alles auswählen

import requests
with requests.session() as c:
    url='https://xenforo.com/community/login/login'
    USERNAME='minneconsin@gmail.com'
    PASSWORD='Demo12345'
    c.get(url)
    login_data=dict(login=USERNAME,password=PASSWORD,next="/")
    c.post(url,data=login_data,headers={"Referer":"https://xenforo.com/community/"})

    values='This is auto reply'
    url2='https://xenforo.com/community/threads/nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp.3864/'
    r=c.post(url2,data=values)
    page=c.get('https://xenforo.com/community/threads/nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp-nbsp.3864/page-2')
    print(page.content)
No error but can't add comment "this is auto test" to that topic. Please help me fix it.
BlackJack

@wichit12: You'll have to do what a browser would do to add a reply. The Firebug addon for Firefox can be useful to analyse the communication between the browser and the server while adding a post manually.
wichit12
User
Beiträge: 4
Registriert: Freitag 19. Dezember 2014, 14:29

@BlackJack

Can you help me fix my code?. Tks a lot
Antworten