I can't understand why if i launch this, fill the registration form in github and click "sign up" post data is {}. I'm using python 3.7, cefpython 66.0 code:
import tkinter as tk
from tkinter import messagebox
from cefpython3 import cefpython as cef
#import cefpython3
import threading
import sys
import time
import webbrowser
def on_browse(browser,frame,request,user_gesture,is_redirect):
if user_gesture == True:
print('user_gesture:',user_gesture)
print('GetFirstPartyForCookies:',request.GetFirstPartyForCookies())
print('GetFlags',request.GetFlags())
print('GetHeaderMap',request.GetHeaderMap())
print('GetHeaderMultimap',request.GetHeaderMultimap())
print('GetMethod',request.GetMethod())
print('GetPostData',request.GetPostData())
print('GetUrl',request.GetUrl())
def test_thread(frame):
global browser
sys.excepthook = cef.ExceptHook
window_info = cef.WindowInfo(frame.winfo_id())
window_info.SetAsChild(frame.winfo_id(), rect)
cef.Initialize()
browser = cef.CreateBrowserSync(window_info, url='http://www.github.com')
browser.SetClientCallback('OnBeforeBrowse',on_browse)
cef.MessageLoop()
def on_closing():
print('closing')
r.destroy()
r = tk.Tk()
r.geometry('800x600')
r.protocol('WM_DELETE_WINDOW', on_closing)
frame = tk.Frame(r, bg='blue', height=400)
frame2 = tk.Frame(r, bg='white', height=200)
frame.pack(side='top', fill='x')
frame2.pack(side='top', fill='x')
r.update()
tk.Button(frame2, text='Exit', command=on_closing).pack(side='left')
tk.Button(frame2, text='Show something',
command=lambda: messagebox.showinfo('TITLE', 'Shown something')).pack(side='right')
rect = [0, 0, frame.winfo_width(), frame.winfo_height()]
print('browser: ', rect[2], 'x', rect[3])
thread = threading.Thread(target=test_thread, args=(frame,))
thread.start()
r.mainloop()
and this is how i fill the form
output:
browser: 800 x 400
user_gesture: True
GetFirstPartyForCookies:
GetFlags 0
GetHeaderMap {}
GetHeaderMultimap []
GetMethod POST
GetPostData {}
GetUrl https://github.com/join
closing
>>>
i was expecting to find something in GetPostData. Thanks to everyone that will help me!
****UPDATE**** as suggested I tried with official cefpython tkinter example. I added
self.browser.SetClientCallback('OnBeforeResourceLoad',self.on_browse)
in class browserFrame def embed_browser. Then i add this function before "def embed_browser"
def on_browse(self, browser,frame,request):
user_gesture = True
if user_gesture == True:
print('user_gesture:',user_gesture)
print('GetFirstPartyForCookies:',request.GetFirstPartyForCookies())
print('GetFlags',request.GetFlags())
print('GetHeaderMap',request.GetHeaderMap())
print('GetHeaderMultimap',request.GetHeaderMultimap())
print('GetMethod',request.GetMethod())
print('GetPostData',request.GetPostData())
print('GetUrl',request.GetUrl())
I got this output:
user_gesture: True
GetFirstPartyForCookies: https://github.com/join
GetFlags 0
GetHeaderMap {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 'Content-Type': 'application/x-www-form-urlencoded', 'Origin': 'https://github.com', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36'}
GetHeaderMultimap [('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'), ('Content-Type', 'application/x-www-form-urlencoded'), ('Origin', 'https://github.com'), ('Upgrade-Insecure-Requests', '1'), ('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36')]
GetMethod POST
[CEF Python] ExceptHook: catched exception, will shutdown CEF
Traceback (most recent call last):
File "request_handler.pyx", line 117, in cefpython_py37.RequestHandler_OnBeforeResourceLoad
File "C:\Users\*****\Desktop\tkinter_.py", line 166, in on_browse
print('GetPostData',request.GetPostData())
File "request.pyx", line 83, in cefpython_py37.PyRequest.GetPostData
File "request.pyx", line 122, in cefpython_py37.PyRequest.GetPostData
File "C:\Python37\lib\urllib\parse.py", line 740, in parse_qsl
value = _coerce_result(value)
File "C:\Python37\lib\urllib\parse.py", line 103, in _encode_result
return obj.encode(encoding, errors)
UnicodeEncodeError: 'ascii' codec can't encode character '\u2713' in position 0: ordinal not in range(128)