Cloud Natural Language API Python script error (Client object has no attribute create_rows)

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Cloud Natural Language API Python script error (Client object has no attribute create_rows)



I was trying to create a script that feeds articles through the classification tool of the natural language api and I found a tutorial that does exatcly that. I was following this simple tutorial to get an intro into google cloud and the natural language api.



The end result is supposed to be a script that sends a bunch of news articles from the google cloud storage to the natural language api to classify the articles and the save the whole thing into a table created in bigquery.



I was following the example fine, but when running the final script I get the following error:


Traceback (most recent call last):
File "classify-text.py", line 39, in <module>
errors = bq_client.create_rows(table, rows_for_bq)
AttributeError: 'Client' object has no attribute 'create_rows'



The full script is:


from google.cloud import storage, language, bigquery

# Set up our GCS, NL, and BigQuery clients
storage_client = storage.Client()
nl_client = language.LanguageServiceClient()
# TODO: replace YOUR_PROJECT with your project name below
bq_client = bigquery.Client(project='Your_Project')

dataset_ref = bq_client.dataset('news_classification')
dataset = bigquery.Dataset(dataset_ref)
table_ref = dataset.table('article_data')
table = bq_client.get_table(table_ref)

# Send article text to the NL API's classifyText method
def classify_text(article):
response = nl_client.classify_text(
document=language.types.Document(
content=article,
type=language.enums.Document.Type.PLAIN_TEXT
)
)
return response


rows_for_bq =
files = storage_client.bucket('text-classification-codelab').list_blobs()
print("Got article files from GCS, sending them to the NL API (this will take ~2 minutes)...")

# Send files to the NL API and save the result to send to BigQuery
for file in files:
if file.name.endswith('txt'):
article_text = file.download_as_string()
nl_response = classify_text(article_text)
if len(nl_response.categories) > 0:
rows_for_bq.append((article_text, nl_response.categories[0].name, nl_response.categories[0].confidence))

print("Writing NL API article data to BigQuery...")
# Write article text + category data to BQ
errors = bq_client.create_rows(table, rows_for_bq)
assert errors ==





You appear to be using code designed for an older version of the library. The create_rows() method was deprecated in version 0.29.
– Martijn Pieters
1 min ago




create_rows()









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

FY4Kl6gCHottpxzndSlB,Jn07nv T8nG,k9RFI25XtwpLRjDZB,0OLNcYlEIBu275
ZdPe3CIID,neJMEcrpjs1j,A94,pA AmvpQYoW xzu3Gfl9 ZX,X R,Us1nxJwn,RHcGCZp5enKOiwRiD1BrfsqKD,caB,0F

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results