Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With version 0.7.2, I get this error when I attempt to xlwings.Workbook.caller() #498

Closed
ededovic opened this issue Jun 27, 2016 · 29 comments

Comments

@ededovic
Copy link

ededovic commented Jun 27, 2016

2.7.11 |Anaconda 4.0.0 (64-bit)| (default, Feb 16 2016, 09:58:36) [MSC v.1500 64 bit (AMD64)]
xlwings version: 0.7.2, path: 'C:\Users\hidden\AppData\Local\Continuum\Anaconda2\lib\site-packages\xlwings'

This is trace back of the error:

Error

Traceback (most recent call last):

  File "<string>", line 1, in <module>

  File "hidden.py", line 77, in ...

   wb = xw.Workbook.caller()

  File "C:\Users\hidden\AppData\Local\Continuum\Anaconda2\lib\site-packages\xlwings\main.py", line 236, in caller

    xl_app, xl_workbook = xlplatform.get_open_workbook(fullname, hwnd=sys.argv[4])

  File "C:\Users\hidden\AppData\Local\Continuum\Anaconda2\lib\site-packages\xlwings\_xlwindows.py", line 142, in get_open_workbook

    duplicate_fullnames = get_duplicate_fullnames()

  File "C:\Users\hidden\AppData\Local\Continuum\Anaconda2\lib\site-packages\xlwings\_xlwindows.py", line 124, in get_duplicate_fullnames

    for xl_app in get_xl_apps():

  File "C:\Users\hidden\AppData\Local\Continuum\Anaconda2\lib\site-packages\xlwings\_xlwindows.py", line 96, in get_xl_apps

    xl_app = get_xl_app_from_hwnd(hwnd)

  File "C:\Users\hidden\AppData\Local\Continuum\Anaconda2\lib\site-packages\xlwings\_xlwindows.py", line 73, in get_xl_app_from_hwnd

    return disp.Application

  File "C:\Users\hidden\AppData\Local\Continuum\Anaconda2\lib\site-packages\win32com\client\dynamic.py", line 527, in __getattr__

    raise AttributeError("%s.%s" % (self._username_, attr))

AttributeError: <unknown>.Application



Press Ctrl+C to copy this message to the clipboard.

OK

@fzumstein
Copy link
Member

Does this happen when you call the script via RunPython from Excel? Or how are you calling it?

@ededovic
Copy link
Author

ededovic commented Jun 27, 2016

When I call RunPython.
RunPython ("import module_name; module_name.source_of_difference_to_excel()")

@fzumstein
Copy link
Member

When you download and unzip the fibonacci Lite sample from the homepage, do you get the same behavior?

@ededovic
Copy link
Author

I have not tried that. It used to work fine with prior version I think 0.6.4. When I upgraded to 0.7.2 it stopped. May be I'll just go back.

What could be causing this type of issue?

@fzumstein
Copy link
Member

Make sure to also upgrade the xlwings VBA module...

@ededovic
Copy link
Author

I did that too.

@fzumstein
Copy link
Member

it's hard to tell what's going on. Knowing if a clean fibonacci sample works would help. Also, what version of Excel are you using?

@nerdnum
Copy link

nerdnum commented Jul 19, 2016

Hi Guys

We get the same issue.
In the line xl_app, xl_workbook = xlplatform.get_open_workbook(fullname, hwnd=sys.argv[4]) it is looking for a command line argument, which I guess it receives when RunPython is invoked in Excel.
This is running on either Windows7 or Windows10.

However, in our case, there is only 3 command line arguments:

  1. "-c"
  2. "\path\and\name\of\file.xlsm,
  3. xl_form"

I have created a little workaround for now. In file main.py Class Workbook I have edited the caller(cls) class method and added lines as follows:

        if hasattr(Workbook, '_mock_file'):
            # Use mocking Workbook, see Workbook.set_mock_caller()
            _, xl_workbook = xlplatform.get_open_workbook(Workbook._mock_file)
            return cls(xl_workbook=xl_workbook)          
        elif len(sys.argv) > 2 and sys.argv[2] == 'from_xl':
            # Connect to the workbook from which this code has been invoked
            fullname = sys.argv[1].lower()
            if sys.platform.startswith('win'):

## This is my code ##

                hwnd = None
                try:
                    hwnd = sys.argv[4]
                except:
                    pass
                xl_app, xl_workbook = xlplatform.get_open_workbook(fullname, hwnd=hwnd)

## This is my code ##

                return cls(xl_workbook=xl_workbook)
            else:
                xl_app, xl_workbook = xlplatform.get_open_workbook(fullname, app_target=sys.argv[3])
                return cls(xl_workbook=xl_workbook, app_target=sys.argv[3])
        elif xlplatform.get_xl_workbook_current():
            # Called through ExcelPython connection
            return cls(xl_workbook=xlplatform.get_xl_workbook_current())
        else:
            raise Exception('Workbook.caller() must not be called directly. Call through Excel or set a mock caller '
                            'first with Workbook.set_mock_caller().')

I believe this is a bug. As the code clearly expect more command line paramters which are not being provided. Looking forward to it being fixed.

Kind Regards
Nerdnum

@fzumstein
Copy link
Member

are you sure you're running the same version of the VBA module as the
python package? or, when you download and unzip the fibonacci sample from
the homepage, do you get the same error?

Am 19.07.2016 2:48 nachm. schrieb "nerdnum" notifications@github.com:

Hi Guys

We get the same issue.
In the line xl_app, xl_workbook = xlplatform.get_open_workbook(fullname,
hwnd=sys.argv[4]) it is looking for a command line argument, which I
guess it receives when RunPython is invoked in Excel.
This is running on either Windows7 or Windows10.

However, in our case, there is only 3 command line arguments:

  1. "-c"
  2. "\path\and\name\of\file.xlsm,
  3. xl_form"

I have created a little workaround for now. In file main.py Class Workbook
I have edited the caller(cls) class method and added lines as follows:

if hasattr(Workbook, '_mock_file'):

Use mocking Workbook, see Workbook.set_mock_caller()

_, xl_workbook = xlplatform.get_open_workbook(Workbook._mock_file)
return cls(xl_workbook=xl_workbook)
elif len(sys.argv) > 2 and sys.argv[2] == 'from_xl':

Connect to the workbook from which this code has been invoked

fullname = sys.argv[1].lower()
if sys.platform.startswith('win'):
hwnd = None
try:
hwnd = sys.argv[4]
except:
pass
xl_app, xl_workbook = xlplatform.get_open_workbook(fullname, hwnd=hwnd)
return cls(xl_workbook=xl_workbook)
else:
xl_app, xl_workbook = xlplatform.get_open_workbook(fullname,
app_target=sys.argv[3])
return cls(xl_workbook=xl_workbook, app_target=sys.argv[3])
elif xlplatform.get_xl_workbook_current():

Called through ExcelPython connection

return cls(xl_workbook=xlplatform.get_xl_workbook_current())
else:
raise Exception('Workbook.caller() must not be called directly. Call
through Excel or set a mock caller '
'first with Workbook.set_mock_caller().')

I believe this is a bug. As the code clearly expect more command line
paramters which are not being provided. Looking forward to it being fixed.

Kind Regards
Louis


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#498 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACKRoJhGVYx8Z6eUYrldecwOcH8mW_xGks5qXMedgaJpZM4I_DEx
.

@nerdnum
Copy link

nerdnum commented Jul 20, 2016

Will get back to you.

On 19 July 2016 at 19:54, Felix Zumstein notifications@github.com wrote:

are you sure you're running the same version of the VBA module as the
python package? or, when you download and unzip the fibonacci sample from
the homepage, do you get the same error?

Am 19.07.2016 2:48 nachm. schrieb "nerdnum" notifications@github.com:

Hi Guys

We get the same issue.
In the line xl_app, xl_workbook = xlplatform.get_open_workbook(fullname,
hwnd=sys.argv[4]) it is looking for a command line argument, which I
guess it receives when RunPython is invoked in Excel.
This is running on either Windows7 or Windows10.

However, in our case, there is only 3 command line arguments:

  1. "-c"
  2. "\path\and\name\of\file.xlsm,
  3. xl_form"

I have created a little workaround for now. In file main.py Class
Workbook
I have edited the caller(cls) class method and added lines as follows:

if hasattr(Workbook, '_mock_file'):

Use mocking Workbook, see Workbook.set_mock_caller()

_, xl_workbook = xlplatform.get_open_workbook(Workbook._mock_file)
return cls(xl_workbook=xl_workbook)
elif len(sys.argv) > 2 and sys.argv[2] == 'from_xl':

Connect to the workbook from which this code has been invoked

fullname = sys.argv[1].lower()
if sys.platform.startswith('win'):
hwnd = None
try:
hwnd = sys.argv[4]
except:
pass
xl_app, xl_workbook = xlplatform.get_open_workbook(fullname, hwnd=hwnd)
return cls(xl_workbook=xl_workbook)
else:
xl_app, xl_workbook = xlplatform.get_open_workbook(fullname,
app_target=sys.argv[3])
return cls(xl_workbook=xl_workbook, app_target=sys.argv[3])
elif xlplatform.get_xl_workbook_current():

Called through ExcelPython connection

return cls(xl_workbook=xlplatform.get_xl_workbook_current())
else:
raise Exception('Workbook.caller() must not be called directly. Call
through Excel or set a mock caller '
'first with Workbook.set_mock_caller().')

I believe this is a bug. As the code clearly expect more command line
paramters which are not being provided. Looking forward to it being
fixed.

Kind Regards
Louis


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<
#498 (comment)
,
or mute the thread
<
https://github.com/notifications/unsubscribe-auth/ACKRoJhGVYx8Z6eUYrldecwOcH8mW_xGks5qXMedgaJpZM4I_DEx

.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#498 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADyGiOWYHHm-8Prbs3Q7-_1zdE7aIKIGks5qXR1VgaJpZM4I_DEx
.

@nerdnum
Copy link

nerdnum commented Jul 20, 2016

Deleted and reimported xlwings.bas and it is now working without my mod.

Thanks

On 20 July 2016 at 09:51, Louis Becker louis.h.becker@gmail.com wrote:

Will get back to you.

On 19 July 2016 at 19:54, Felix Zumstein notifications@github.com wrote:

are you sure you're running the same version of the VBA module as the
python package? or, when you download and unzip the fibonacci sample from
the homepage, do you get the same error?

Am 19.07.2016 2:48 nachm. schrieb "nerdnum" notifications@github.com:

Hi Guys

We get the same issue.
In the line xl_app, xl_workbook = xlplatform.get_open_workbook(fullname,
hwnd=sys.argv[4]) it is looking for a command line argument, which I
guess it receives when RunPython is invoked in Excel.
This is running on either Windows7 or Windows10.

However, in our case, there is only 3 command line arguments:

  1. "-c"
  2. "\path\and\name\of\file.xlsm,
  3. xl_form"

I have created a little workaround for now. In file main.py Class
Workbook
I have edited the caller(cls) class method and added lines as follows:

if hasattr(Workbook, '_mock_file'):

Use mocking Workbook, see Workbook.set_mock_caller()

_, xl_workbook = xlplatform.get_open_workbook(Workbook._mock_file)
return cls(xl_workbook=xl_workbook)
elif len(sys.argv) > 2 and sys.argv[2] == 'from_xl':

Connect to the workbook from which this code has been invoked

fullname = sys.argv[1].lower()
if sys.platform.startswith('win'):
hwnd = None
try:
hwnd = sys.argv[4]
except:
pass
xl_app, xl_workbook = xlplatform.get_open_workbook(fullname, hwnd=hwnd)
return cls(xl_workbook=xl_workbook)
else:
xl_app, xl_workbook = xlplatform.get_open_workbook(fullname,
app_target=sys.argv[3])
return cls(xl_workbook=xl_workbook, app_target=sys.argv[3])
elif xlplatform.get_xl_workbook_current():

Called through ExcelPython connection

return cls(xl_workbook=xlplatform.get_xl_workbook_current())
else:
raise Exception('Workbook.caller() must not be called directly. Call
through Excel or set a mock caller '
'first with Workbook.set_mock_caller().')

I believe this is a bug. As the code clearly expect more command line
paramters which are not being provided. Looking forward to it being
fixed.

Kind Regards
Louis


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<
#498 (comment)
,
or mute the thread
<
https://github.com/notifications/unsubscribe-auth/ACKRoJhGVYx8Z6eUYrldecwOcH8mW_xGks5qXMedgaJpZM4I_DEx

.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#498 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADyGiOWYHHm-8Prbs3Q7-_1zdE7aIKIGks5qXR1VgaJpZM4I_DEx
.

@ededovic
Copy link
Author

I downloaded fibonaci sample from the home page and got the same error message:

Error

Traceback (most recent call last):

File "", line 1, in

File "c:\users\test\downloads\fibonacci.py", line 28, in xl_fibonacci

wb = Workbook.caller()

File "C:\Users\test\AppData\Local\Continuum\Anaconda2\lib\site-packages\xlwings\main.py", line 236, in caller

xl_app, xl_workbook = xlplatform.get_open_workbook(fullname, hwnd=sys.argv[4])

File "C:\Users\test\AppData\Local\Continuum\Anaconda2\lib\site-packages\xlwings_xlwindows.py", line 142, in get_open_workbook

duplicate_fullnames = get_duplicate_fullnames()

File "C:\Users\test\AppData\Local\Continuum\Anaconda2\lib\site-packages\xlwings_xlwindows.py", line 124, in get_duplicate_fullnames

for xl_app in get_xl_apps():

File "C:\Users\test\AppData\Local\Continuum\Anaconda2\lib\site-packages\xlwings_xlwindows.py", line 96, in get_xl_apps

xl_app = get_xl_app_from_hwnd(hwnd)

File "C:\Users\test\AppData\Local\Continuum\Anaconda2\lib\site-packages\xlwings_xlwindows.py", line 73, in get_xl_app_from_hwnd

return disp.Application

File "C:\Users\test\AppData\Local\Continuum\Anaconda2\lib\site-packages\win32com\client\dynamic.py", line 527, in getattr

raise AttributeError("%s.%s" % (self._username_, attr))

AttributeError: .Application

Press Ctrl+C to copy this message to the clipboard.

OK

@fzumstein
Copy link
Member

@ededovic do you have v0.7.2 installed?

>>> import xlwings
>>> xlwings.__version__

@fzumstein
Copy link
Member

Closing this due to inactivity. feel free to reopen.

@ededovic
Copy link
Author

Thanks for attending to the issue. I think the new version 0.9+ has somehow addressed this issue. I've been using it for the past several weeks, and it works fine.

@akasolace
Copy link

I have that issue when I got some ghosts excel instances.
To solve this I need to close all excel then kill all remaining excel process from the task manager, and then reopen excel

@idahopotato1
Copy link

I am having this issue after updated the version to 15. My other computer had 11.8 and it is working fine.
On the new computer, when I call python from excel, it says Exception('Workbook.caller() must not be called directly. Call
through Excel or set a mock caller '
'first with Workbook.set_mock_caller().')
I tried both Workbook.call() and Book.call. Neither is working. Is there any fix? Thanks

@fzumstein
Copy link
Member

@idahopotato1 please run "xlwings runpython install" if you are on mac to fix this.

@idahopotato1
Copy link

I am on windows.

@fzumstein
Copy link
Member

Can you please share code and traceback?

@idahopotato1
Copy link

I tried the fibonacci sample and got the same thing.


Error

Traceback (most recent call last):

File "", line 1, in

File "...\downloads\fibonacci\fibonacci.py", line 28, in xl_fibonacci

sht = xw.Book.caller().sheets[0]

File "...\AppData\Local\Continuum\anaconda3\lib\site-packages\xlwings\main.py", line 570, in caller

raise Exception('Workbook.caller() must not be called directly. Call through Excel or set a mock caller '

Exception: Workbook.caller() must not be called directly. Call through Excel or set a mock caller first with Book.set_mock_caller().

Press Ctrl+C to copy this message to the clipboard.

OK

@idahopotato1
Copy link

is there anyway I can go back to 11.8 version? Thank you so much. I have a lot of things in the work and really need this to work for now. :)

@fzumstein
Copy link
Member

fzumstein commented Mar 19, 2019

pip install xlwings==0.11.8

@idahopotato1
Copy link

sorry about all the troubles. But it says the following.

Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: TLSV1_ALERT_ACCESS_DENIED] tlsv1 alert access denied (_ssl.c:1056)'))': /packages/64/27/4068e0abbc2753a13fa0d7eccb502f61b80128c449e501018d2af20eeb70/xlwings-0.11.8.tar.gz
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: TLSV1_ALERT_ACCESS_DENIED] tlsv1 alert access denied (_ssl.c:1056)'))': /packages/64/27/4068e0abbc2753a13fa0d7eccb502f61b80128c449e501018d2af20eeb70/xlwings-0.11.8.tar.gz
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: TLSV1_ALERT_ACCESS_DENIED] tlsv1 alert access denied (_ssl.c:1056)'))': /packages/64/27/4068e0abbc2753a13fa0d7eccb502f61b80128c449e501018d2af20eeb70/xlwings-0.11.8.tar.gz
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: TLSV1_ALERT_ACCESS_DENIED] tlsv1 alert access denied (_ssl.c:1056)'))': /packages/64/27/4068e0abbc2753a13fa0d7eccb502f61b80128c449e501018d2af20eeb70/xlwings-0.11.8.tar.gz
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: TLSV1_ALERT_ACCESS_DENIED] tlsv1 alert access denied (_ssl.c:1056)'))': /packages/64/27/4068e0abbc2753a13fa0d7eccb502f61b80128c449e501018d2af20eeb70/xlwings-0.11.8.tar.gz
Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/64/27/4068e0abbc2753a13fa0d7eccb502f61b80128c449e501018d2af20eeb70/xlwings-0.11.8.tar.gz (Caused by SSLError(SSLError(1, '[SSL: TLSV1_ALERT_ACCESS_DENIED] tlsv1 alert access denied (_ssl.c:1056)')))

@fzumstein
Copy link
Member

this is a pip issue, download from pypi directly, then say pip install C:\path\to\downloaded\xlwings...

@idahopotato1
Copy link

I was able to go back with conda install xlwings==0.11.8
let me try if it works now. Thank you

@idahopotato1
Copy link

Everything works now. Thank you so much for your quick response. I really like your product.
Please let me know if you will be able to find out why v. 15 has this problem. It will be super helpful. I really want to use the feature to interact with outlook in the newer version.

@fzumstein
Copy link
Member

I am not aware of an issue with the latest version. was the add-in the same version as the python package?

@idahopotato1
Copy link

I did try xlwings addin update a couple of times. Now I know how to fix the problem, I can try a few different things to reproduce it if that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants