Re: [python-win32] Need data type identifiers

2012-07-23 Thread Graham Bloice
This issue sometimes occurs when the typelib specifies a VARIANT type
argument, implying that any VARIANT type will do, but the COM server is
coded to expect an actual type and does not (incorrectly IMHO) attempt to
convert the incoming VARIANT to the appropriate type.  Makepy has no idea
of what type is really expected so I think converts the parameter based on
the Python type of the value passed in the call.  This may or may not line
up with what the COM Server is expecting.



When this occurs, and you don’t have access to the COM Server code to fix
it, you must force the COM Client to pass the appropriate types.
“Adjusting” the makepy generated file is one way of doing this.



*From:* python-win32-bounces+graham.bloice=trihedral@python.org [mailto:
python-win32-bounces+graham.bloice=trihedral@python.org] *On
Behalf Of *Fox,
Michael K
*Sent:* 21 July 2012 04:55
*To:* python-win32@python.org
*Subject:* [python-win32] Need data type identifiers



We are having occasional difficulties when we need to pass an argument
in-and-out of a COM method that we are calling in Python.  There is some
magic in makepy that normally handles this for us but occasionally it fails
because it somehow reads the typelib incorrectly and misunderstands the
data type it must create.  Specifically, I have a C++ method exposed to COM
and it expects an empty SafeArray of two elements (double floats) to be
passed as an argument.  That method revises the array, filling it with two
values.  We have found that makepy assigns some sort of identifier to each
data type.  For instance an array of strings is assigned (24584, 3) and an
array of variants is assigned (24588, 3) as shown in the line of code
below, taken from one of the wrappers created by Makepy.



def *GetDirection*(*self*, oDirection=(0,0)):

  return *self*._ApplyTypes_(1611137025, 1, (24, 0), ((24588,3),),
u*'GetDirection'*, None, oDirection)



Occasionally pywin32 assigns the wrong identifier then the argument is cast
as the wrong data type and an error is thrown.  We stumbled upon the
correct identifier and when we corrected the identifier assigned by Makepy
then we were able to call the method without throwing an error.  Where can
we find a list of these identifiers?



*Mike Fox*
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] py2exe issues with script using selenium

2012-07-23 Thread Ferdinand Sousa
Hi Mark,

I tried extracting the files inside webdriver.xpi into a folder
webdriverxpi and placed it in lieu of the former in the zip file. I had to
tweak some code inside the firefox_profile.py file as well, so that it
would add the files inside the webdriverxpi folder to the current path
environment. Some thing like:

##
-
WEBDRIVER_EXT = "webdriver.xpi" ## changed this to "webdriverxpi"
. later in the code 
 if addon == WEBDRIVER_EXT:
addon = os.path.join(os.path.dirname(__file__), WEBDRIVER_EXT)
##
-

It worked. As in, it now no longer gave the error I was getting initially.
But, I faced some other issue with some xml standard lib being included
elsewhere in the selenium include tree (IIRC it was Lib\xml\dom\minidom.py). The issue was similar to that faced earlier,
missing file.

Rather than have to handle every subsequent import issue, I decided to try
a different approach. I ran py2exe with the --skip-archive option, placed
the compressed webdriver.xpi file into the correct location and voila!

Thanks a ton for your help.

What would I have done without you guys?! :-D
Ferdi

PS: Maybe py2exe should include files it does not recognize as is in the
include tree?? Just my 2 cents.


On Wed, Jul 18, 2012 at 8:07 AM, Mark Hammond wrote:

> The problem is a "conflict" between the firefox_profile module and py2exe.
>  firefox_profile is attempting to open 'C:\\Users\\ferdinand\\**
> Desktop\\Landmark_Ops\\dist\\**library.zip\\selenium\\**
> webdriver\\firefox\\webdriver.**xpi' as a regular file (a .xpi file is a
> .zip file, hence the fact zipfile itself is throwing the error), but that
> file doesn't exist as a regular file.
>
> You probably need to look into the source of firefox_profile and see if
> you can tell it where the .xpi file lives.  Then you would take advantage
> of py2exe's "data_files" option to arrange for the .xpi file to be packaged
> as a regular file, then tell firefox_profile where that location is.
>
> HTH,
>
> Mark
>
>
> On 18/07/2012 4:05 AM, Ferdinand Sousa wrote:
>
>> Hi List,
>>
>> My environment: Win 7 Professional 64-bit, Python 2.7 64-bit and
>> appropriate 64-bit libraries installed over that.
>> I downloaded the 64-bit py2exe package. Though I did not specifically
>> download the Distutils package, I guess I have it from having installed
>> 3rd party Python libraries.
>>
>> I'm trying to create a py2exe executable of a script that automates
>> Firefox using selenium webdriver.
>> The script also uses a couple of other libraries including the python
>> imaging library and pywin32.
>>
>> When I try to run the generated exe I get the following traceback: (the
>> 1st 2 lines after the script starts are print statement output)
>>
>> ##**--**
>> --**--**-
>> C:\Users\ferdinand\Desktop\**Landmark_Ops\dist>make_ELOG.**exe
>> Starting CLI commands
>> CLI output parsed
>> Traceback (most recent call last):
>>File "make_ELOG.py", line 220, in 
>>File "selenium\webdriver\firefox\**webdriver.pyc", line 51, in
>> __init__
>>File "selenium\webdriver\firefox\**extension_connection.pyc", line 45,
>> in __init__
>>File "selenium\webdriver\firefox\**firefox_profile.pyc", line 136, in
>> add_extension
>>File "selenium\webdriver\firefox\**firefox_profile.pyc", line 289, in
>> _install_extension
>>File "zipfile.pyc", line 701, in __init__
>> IOError: [Errno 2] No such file or directory:
>> 'C:\\Users\\ferdinand\\**Desktop\\Landmark_Ops\\dist\\**
>> library.zip\\selenium\\**webdriver\\firefox\\webdriver.**xpi'
>> ##**--**
>> --**--**-
>>
>> I checked the zip folder mentioned in the path and it is missing the
>> webdriver.xpi file.
>> I manually added the missing file into the zip folder from a similar
>> path in my python setup, but it still doesn't work.
>> The start of the traceback ( line 220, in  ) refers to the line
>> where I 1st instantiate the Firefox() selenium webdriver automation
>> object.
>>
>> I had earlier tried the same with pyinstaller and faced a similar kind
>> of issue with the same webdriver.xpi file. It that case, pyinstaller
>> used some other file format (not zip) and I was not able to edit that
>> file.
>>
>> The script works quite ok in the normal python environment.
>> Any pointers?
>>
>> Thanks,
>> Ferdi
>>
>>
>> __**_
>> python-win32 mailing list
>> python-win32@python.org
>> http://mail.python.org/**mailman/listinfo/python-win32
>>
>>
>
___
python-win32 mailing list
pyt

Re: [python-win32] python-win32 Digest, Vol 112, Issue 19

2012-07-23 Thread Jane Chen
Thank you for your help! No luck so far.

I wrote a C program and got the same results as python:
Win 7 Notebook (with SD card inserted directly i.e. no SD card reader) Error 
code: 1
Win 7 Notebook (without SD card inserted at all) Error code: 6
WinXP desktop (with USB stick but without SD card inserted at all) Error code: 
50


int main(int argc, char* argv[])
{
 string sdrive(".\\e:");   
 HANDLE hcd = CreateFile(sdrive.c_str(), 
  GENERIC_READ, 
  FILE_SHARE_READ|FILE_SHARE_WRITE,
  NULL, 
  OPEN_EXISTING, 
  FILE_ATTRIBUTE_READONLY, 
  NULL);
 
 if (hcd == INVALID_HANDLE_VALUE)
  printf("Could not open drive\\\n");
 else
  printf ("%s \n", "opened drive");
 
 DWORD d = 0;
 int nSizeOfCmd = sizeof(SFFDISK_QUERY_DEVICE_PROTOCOL_DATA) ;
 SFFDISK_QUERY_DEVICE_PROTOCOL_DATA *pCmdBuf = 
(SFFDISK_QUERY_DEVICE_PROTOCOL_DATA*) new BYTE[nSizeOfCmd];
 memset(pCmdBuf, 0, nSizeOfCmd);  
 BOOL bResult=DeviceIoControl(hcd, IOCTL_SFFDISK_QUERY_DEVICE_PROTOCOL, NULL, 
0, 
 pCmdBuf, nSizeOfCmd, &d, NULL);
 DWORD dwErr = GetLastError();
 CloseHandle(hcd);
 if(!bResult){
      printf("Failed to get ProtocolGUID, err code: %d",dwErr);
      
 }
 else{
 printf("%s \n", pCmdBuf->ProtocolGUID);
 }
 
 delete [] pCmdBuf;
 return 0;
 
}

Thank you,
Jane

Jane Chen wrote:
> Sorry. It's a mistake. However, I still get the same error message.
> Maybe there is another mistake. :(
> Is there any tool for debugging purpose?

What I would do is write the code as a C program just to make sure the
API does what I expect.  That at least eliminates the Python layers from
consideration.

What SD card reader are you using?  Not all of the behave nicely.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.



-
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Does pywin32 support SD card operation(IOCTL_SFFDISK_QUERY_DEVICE_PROTOCOL)?

2012-07-23 Thread Jane Chen
Sorry! I forgot to change the subject in the previous email.


Thank you for your help! No luck so far.

I wrote a C program and got the same results as python:
Win 7 Notebook (with SD card inserted directly i.e. no SD card reader) Error 
code: 1
Win 7 Notebook (without SD card inserted at all) Error code: 6
WinXP desktop (with USB stick but without SD card inserted at all) Error code: 
50


int main(int argc, char* argv[])
{
 string sdrive(".\\e:");   
 HANDLE hcd = CreateFile(sdrive.c_str(), 
  GENERIC_READ, 
  FILE_SHARE_READ|FILE_SHARE_WRITE,
  NULL, 
  OPEN_EXISTING, 
  FILE_ATTRIBUTE_READONLY, 
  NULL);
 
 if (hcd == INVALID_HANDLE_VALUE)
  printf("Could not open drive\\\n");
 else
  printf ("%s \n", "opened drive");
 
 DWORD d = 0;
 int nSizeOfCmd = sizeof(SFFDISK_QUERY_DEVICE_PROTOCOL_DATA) ;
 SFFDISK_QUERY_DEVICE_PROTOCOL_DATA *pCmdBuf = 
(SFFDISK_QUERY_DEVICE_PROTOCOL_DATA*) new BYTE[nSizeOfCmd];
 memset(pCmdBuf, 0, nSizeOfCmd);  
 BOOL bResult=DeviceIoControl(hcd, IOCTL_SFFDISK_QUERY_DEVICE_PROTOCOL, NULL, 
0, 
 pCmdBuf, nSizeOfCmd, &d, NULL);
 DWORD dwErr = GetLastError();
 CloseHandle(hcd);
 if(!bResult){
      printf("Failed to get ProtocolGUID, err code: %d",dwErr);
      
 }
 else{
 printf("%s \n", pCmdBuf->ProtocolGUID);
 }
 
 delete [] pCmdBuf;
 return 0;
 
}

Thank you,
Jane

Jane Chen wrote:
> Sorry. It's a mistake. However, I still get the same error message.
> Maybe there is another mistake. :(
> Is there any tool for debugging purpose?

What I would do is write the code as a C program just to make sure the
API does what I expect.  That at least eliminates the Python layers from
consideration.

What SD card reader are you using?  Not all of the behave nicely.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.



-___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Need data type identifiers

2012-07-23 Thread Tim Roberts
Fox, Michael K wrote:
>
> ...
>
>  
>
> def*GetDirection*(/self/, oDirection=(0,0)):
>
>   return/self/._ApplyTypes_(1611137025, 1, (24, 0),
> ((24588,3),), u/'GetDirection'/, None, oDirection)
>
>  
>
> Occasionally pywin32 assigns the wrong identifier then the argument is
> cast as the wrong data type and an error is thrown.  We stumbled upon
> the correct identifier and when we corrected the identifier assigned
> by Makepy then we were able to call the method without throwing an
> error.  Where can we find a list of these identifiers?
>

Some day, I will write this down instead of having to go look for it
every time.  The master reference for this information is the include
file  which is part of the Windows SDK.  That has a very short
explanation of each type, plus the numeric value.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] python-win32 Digest, Vol 112, Issue 19

2012-07-23 Thread Tim Roberts
Jane Chen wrote:
> Thank you for your help! No luck so far.
>
> I wrote a C program and got the same results as python:

Support for this ioctl is sporadic.  It may simply be that your SD drive
doesn't support it.

> Win 7 Notebook (with SD card inserted directly i.e. no SD card
> reader) Error code: 1

ERROR_INVALID_FUNCTION.  There has to be an SD card reader somewhere.

> Win 7 Notebook (without SD card inserted at all) Error code: 6

ERROR_INVALID_HANDLE

> WinXP desktop (with USB stick but without SD card inserted at
> all) Error code: 50

ERROR_FILE_EXISTS?  Remember that a USB stick will never support this.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Need data type identifiers

2012-07-23 Thread Mark Hammond
All the other comments in this thread are correct, but one other thing 
you can do in recent pywin32 builds is to use win32com.client.VARIANT to 
override how a value is passed - search for 'win32com.client.VARIANT' in 
pywin32.chm for basic docs.


HTH,

Mark

On 21/07/2012 1:55 PM, Fox, Michael K wrote:

We are having occasional difficulties when we need to pass an argument
in-and-out of a COM method that we are calling in Python.  There is some
magic in makepy that normally handles this for us but occasionally it
fails because it somehow reads the typelib incorrectly and
misunderstands the data type it must create.  Specifically, I have a C++
method exposed to COM and it expects an empty SafeArray of two elements
(double floats) to be passed as an argument.  That method revises the
array, filling it with two values.  We have found that makepy assigns
some sort of identifier to each data type.  For instance an array of
strings is assigned (24584, 3)and an array of variants is assigned
(24588, 3) as shown in the line of code below, taken from one of the
wrappers created by Makepy.

def*GetDirection*(/self/, oDirection=(0,0)):

return/self/._ApplyTypes_(1611137025, 1, (24, 0), ((24588,3),),
u/'GetDirection'/, None, oDirection)

Occasionally pywin32 assigns the wrong identifier then the argument is
cast as the wrong data type and an error is thrown.  We stumbled upon
the correct identifier and when we corrected the identifier assigned by
Makepy then we were able to call the method without throwing an error.
Where can we find a list of these identifiers?

*Mike Fox*



___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32



___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32