3

I am new to Python and working on a project that I could use some help on. So I am trying to modify an existing excel workbook in order to compare stock data. Luckily, there was a program online that retrieved all the data I need and I have successful been able to pull the data and write the data into a new excel file. However, the goal is to pull the data and put it into an existing excel file. Furthermore, I need to overwrite the cell values in the existing file. I believe xlwings is able to do this and I think my code is on the right track, but I ran into an unexpected error. The error I get is:

com_error: (-2147023174, 'The RPC server is unavailable.', None, None)  

I was wondering if anyone knew why this error came up? Also, does anyone know how to fix it? Is it fixable? Is my code wrong? Any help or guidance is appreciated. Thank you.

import good_morning as gm
import pandas as pd
import xlwings as xw

#import income statement, balance sheet, and cash flow of AAPL
fd = gm.FinancialsDownloader()
fd_frames = fd.download('AAPL')

#Creates a DataFrame for only the balance sheet
df1 = pd.DataFrame(list(fd_frames.values())[0])

#connects to workbook I want to modify
wb = xw.Book  (r'C:/Users/vince/OneDrive/Documents/Python/Project/spreadsheet.xlsm')

#sheet I would like to modify
sht = wb.sheets[1]

#modifies & overwrites values in my spreadsheet (this is where I get the commerror)
sht.range('M6').value = df1 
nuiun
  • 764
  • 8
  • 19
vdub32
  • 193
  • 1
  • 5
  • 12

2 Answers2

0

The error message tuple you get indicates that the RPC server you try to connect to is not available. This failure can happen if the RPC server is offline or if your program cannot connect to the network in which the RPC server resides.

The RPC server is unavailable.

RPC stands for Remote Procedure Call. A RPC server is usually another computer residing somewhere else in your network or a network you are connected to. Via the RPC interface you can send function requests with parameters to the server and the server will execute these requests for you and return the apropriate answer. It mimics regular function calls on your machine with the difference that these function calls are executed on the remote RPC server.

From what you wrote in your explanation of the problem I assume you did not mean to contact a remote server at all to do the necessary task. I would suggest removing or replacing code which tries to connect to a remote service by code which works locally on your machine.

This line points onto a directory structure which refers to a directory called OneDrive. Is this a remote directory? Try to place your spreadsheat somewhere else in a folder you are shure is accessible by the user who runs your program and is not a remote directory.

#connects to workbook I want to modify
wb = xw.Book  (r'C:/Users/vince/OneDrive/Documents/Python/Project/spreadsheet.xlsm')

The following lines also imply a connection to the internet, just by word meaning. I am not familiar with the library you are using, so this could also be just some weird nameing of functions. All I am saying here is, that I am not shure.

#import income statement, balance sheet, and cash flow of AAPL
fd = gm.FinancialsDownloader()
fd_frames = fd.download('AAPL')
nuiun
  • 764
  • 8
  • 19
  • Thanks for answering my question because I was really confused. I am still confused because I did not mean to contact a remote server and do not know why a remote server was contacted. I have been researching online to learn how to overwrite to an existing xlsx or xlsm workbook, but the only solution I found was with xlwings. WIth that being said, I don't know if I can replace the code with a better function. Do you have any recommendations or ideas? Once again, thanks for your help – vdub32 Jun 12 '17 at 03:07
  • see @Nicholiae's answer. I'll also extend my answer to point the problem line out in your code ;) – nuiun Jun 12 '17 at 07:36
  • Thank you for your help. I took your advice and placed the file in a directory stored on my computer. The new line of code looks like this: wb = xw.Book(r'C:/Users/vince/Project/Spreadsheet.xlsm'). However, now I am getting a new error. The new error states: com_error: (-2147352570, 'Unknown name.', None, None). I do not know what this error means and cannot find much online on the error. Do you know what this error means? Everything is referenced and spelled correctly – vdub32 Jun 12 '17 at 23:54
  • @vdub32, Do you remember what the solution was to the (-2147352570, 'Unknown name.', None, None) error? I am experiencing the same. – Dervissss Jul 17 '23 at 09:11
0

Your issue is the OneDrive referenced in your directory is not reachable by the program. This can be caused by many things. Improper credentials, OneDrive is off, or simpler the OneDrive does not allow access from a program rather then a user. Try downloading the file you wish to read and write and save it to a directory stored on your computer and point the program to the new directory and see what happens then.

  • Communication between cloud storage and computers is somewhat complicated when you add in programs doing the communication for you. There are a plethora of issues that can be encountered usually improper credentials hard coded into the program and the cloud (OneDrive) having the proper receiver to show access is granted to trusted users. Security measures prevent untrusted access by both programs and users. Just because the user has access does not mean the program on the same system will have it as they are treated as two different user's access by the security measures. – Nicholas Shaffer Jun 12 '17 at 03:21
  • Thank you for your help. I took your advice and placed the file in a directory stored on my computer. The new line of code looks like this: wb = xw.Book(r'C:/Users/vince/Project/Spreadsheet.xlsm'). However, now I am getting a new error. The new error states: com_error: (-2147352570, 'Unknown name.', None, None). I do not know what this error means and cannot find much online on the error. Do you know what this error means? Everything is referenced and spelled correctly – vdub32 Jun 12 '17 at 23:49
  • Trying putting the file in the same folder as the program and point the program to that file. See if the same error persists. Also do u have any import modules? – Nicholas Shaffer Jun 29 '17 at 20:02