![]() |
| AttributeError: 'str' object has no attribute 'name' - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: AttributeError: 'str' object has no attribute 'name' (/thread-29910.html) |
AttributeError: 'str' object has no attribute 'name' - deathsperance - Sep-25-2020 Trying to grab an excel file from azure blob store and put into azure sql server instance. it was working and suddenly stopped. It was running on a coworkers machine and he is using 3.7 I am using 3.8. Hoping someone can see something simple were missing. Getting this error when I run it. 'table_name': tbl.name, AttributeError: 'str' object has no attribute 'name' import io import requests import openpyxl import pandas as pd from sqlalchemy import create_engine import urllib #Target Server Connection String params = urllib.parse.quote_plus(r'Driver={ODBC Driver 17 for SQL Server};Server=servernamehere,1433;Uid=adminuser;Pwd=testpswd;database=Stage;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;') #Blob snapshot URL pulled from azure blob input_excel = requests.get('https://testdata.blob.core.uscloudapi.net/testing6data/testing.xlsx, stream=True) conn_str = 'mssql+pyodbc:///?odbc_connect={}'.format(params) engn = create_engine(conn_str,echo=True) # Loads the excel file into the eb variable wb = openpyxl.load_workbook(filename=io.BytesIO(input_excel.content), data_only='True') tables_dict = {} # Go through each worksheet in the workbook for ws_name in wb.sheetnames: #print(wb.sheetnames) print("") print(f"worksheet name: {ws_name}") ws = wb[ws_name] print(f"tables in worksheet: {len(ws._tables)}") # Get each table in the worksheet for tbl in ws._tables: # First, add some info about the table to the dictionary tables_dict[tbl.name] = { 'table_name': tbl.name, 'worksheet': ws_name, 'num_cols': len(tbl.tableColumns), 'table_range': tbl.ref} # Grab the 'data' from the table data = ws[tbl.ref] # Now convert the table 'data' to a Pandas DataFrame # First get a list of all rows, including the first header row rows_list = [] for row in data: # Get a list of all columns in each row cols = [] for col in row: cols.append(col.value) rows_list.append(cols) # Create a pandas dataframe from the rows_list. # The first row is the column names df = pd.DataFrame(data=rows_list[1:], index=None, columns=rows_list[0]) # Add the dataframe to the dictionary of tables # df = df.dropna(how='any') df.to_sql(tbl.name, engn, if_exists='append',schema='testing') print(df) tables_dict[tbl.name]['dataframe'] = df print('-----------------------------done------------------------') RE: AttributeError: 'str' object has no attribute 'name' - Larz60+ - Sep-25-2020 Please show complete unmodified error traceback. (in error tags) It contains valuable process information on what happened prior to error, and more. RE: AttributeError: 'str' object has no attribute 'name' - deathsperance - Sep-25-2020 Sorry you can delete my post, it was just a simple version error with openpyxl RE: AttributeError: 'str' object has no attribute 'name' - ndc85430 - Sep-25-2020 When something stops working, it's useful to work out what changed in that time, to help narrow down the cause. Did the code change at all? Something in the environment? Does it work on one version of Python and not the other? RE: AttributeError: 'str' object has no attribute 'name' - Larz60+ - Sep-25-2020 Thread/Post Deletion By posting on the forums you agree to the terms of the registration agreement of permitting us to retain that content for our database. You agree that any content you post is under the default MIT license allowing rights to use, copy, modify, merge, publish, distribute, sublicense, and/orThread/Post Deletion see for complete forum rule: https://python-forum.io/misc.php?action=help&hid=32 |