我正在尝试使用图形资源管理器和Python从SharePoint下载文件。
import requests
import pandas as pd
API_ENDPOINT = "my_api_endpoint" #didn't write here as it is classified
API_KEY = "my_api_key" #didn't write here as it is classified
headers = {
"Authorization": f"Bearer {API_KEY}",
"Accept": "application/json"
}
try:
response = requests.get(API_ENDPOINT, headers=headers)
if response.status_code == 200:
data = response.json() # Convert the response to JSON
download_url = data['@microsoft.graph.downloadUrl']
csv_response = requests.get(download_url)
with open('data_dump.csv', 'wb') as csv_file:
csv_file.write(csv_response.content)
df = pd.read_csv('data_dump.csv')
print("CSV file loaded into Pandas DataFrame:\n", df.head())
else:
print(f"Failed to retrieve data. Status code: {response.status_code}")
print("Error message:", response.text)
except requests.exceptions.RequestException as e:
print("An error occurred during the request:", str(e))
但我在误差之下。我试着在互联网上到处找没有多少资源可以解决这个问题。
File "pandas\_libs\parsers.pyx", line 808, in pandas._libs.parsers.TextReader.read_low_memory
File "pandas\_libs\parsers.pyx", line 866, in pandas._libs.parsers.TextReader._read_rows
File "pandas\_libs\parsers.pyx", line 852, in pandas._libs.parsers.TextReader._tokenize_rows
File "pandas\_libs\parsers.pyx", line 1973, in pandas._libs.parsers.raise_parser_error
pandas.errors.ParserError: Error tokenizing data. C error: Expected 4 fields in line 89, saw 5
1条答案
按热度按时间qmelpv7a1#
我不知道Python,但我在谷歌上搜索了你得到的错误消息,我发现了一个帖子,可能会回答你的问题。答案提示您需要在调用
read_csv
时添加编码参数。Error while trying to use pandas to read a csv
我希望这能帮上忙。