Open ctlddey opened 3 years ago
env: python 3.7.9 X86 win10 X64 cefpython 66.1
I was to raise this issue, then found this. I wonder whether there is a work-around (e.g. somehow patching the WebRequest) so that we can use it before the bug is officially fixed. Thanks
This seems to be fixed via https://github.com/cztomczak/cefpython/commit/5679f28cec18a57a56e298da2927aac8d8f83ad6#diff-e4a5fba8f9cbe6d805afd50840dceeed893bf658eee2f58f4ce075d4c4853b2a . You need to build from sources to apply fix. See the quick build instructions in docs.
This fix appeared after the 66.1 release, so you need to pull latest changes from master.
I followed the steps in quick build (I also had to install Windows SDK), but it seems to look explicitly for Win7 SDK and does not work on Win10. Also, I need to run my program on Win10 and Win7 as well, but I can only build on Win10, so probably I need to wait for the new release, I cannot build it myself.
I suspect that even if I could build it from master, I would get stuck in ResourceHandler.ReadResponse, because its data_out[0] has str type, and should also be bytes. Or does it get fixed automatically by commit 5679f28?
ReadResponse data_out[0] is bytes.
When I put this print into my ReadResponse method, It states
And I might have found the reason in handlers/resource_handler.pyx, line 153: dataOut = [""] This initiates the list with an empty string, instead of an empty bytes. It should be: dataOut = [b""]
You can change it to bytes, you set it.
I managed to install Win7 SDK on Win10 and trying to build it from master, but the 66.1 zip package seems to be missing the "lib" folder. Linking "subprocess" fails with not finding the "libcef.lib". Could you please make it available?
You need to download v66-upstream binaries.
This should be explained in Build instructions document. The v66-upstream is a GitHub release tag.
I managed to compile it with the lib as well as the bin copied over from v66-upstream, thanks.
I had to modify resource_handler.pyx, line 165:
if dataOut[0] and IsString(dataOut[0]):
--> if dataOut[0]:
Data is always bytes, not str, i.e. the IsString condition practically would prevent the data to be copied and returned in ResourceHandler_ReadResponse()
Are you sure? IsString name be misleading, I looked at source and it should return true for both bytes and string.
Indeed, IsString() returns True on a bytes object. Well, I see still no point having this check as the data must always be bytes. Unfortunately, the code still does not work in Python3. I checked that the data is right now after it has been corrected to bytes, but it must go wrong somewhere after the ReadResponse(), because the web page still does not display correctly. Can it be caused by the memcpy(), the (&cefBytesRead)[0], or somewhere after ResourceHandler_ReadResponse()?
I'm not sure. You would need to debug.
These PR/issues suggest it should work fine in Python 3 with the commit fix: https://github.com/cztomczak/cefpython/issues/620 https://github.com/cztomczak/cefpython/pull/621 https://github.com/cztomczak/cefpython/commit/5679f28cec18a57a56e298da2927aac8d8f83ad6
Make sure you have this commit applied.
` def OnDownloadData(self, web_request:PyRequest, data:bytes): print("OnDownloadData()", type(data), data)
The api document say the data should be bytes, but I recieved is string,so the web page is broken