Giter Site home page Giter Site logo

Comments (9)

sungchun12 avatar sungchun12 commented on May 28, 2024

Hey nimsim!

I recommend updating the requirements.txt with the latest gbq package. https://pandas-gbq.readthedocs.io/en/latest/

Also, I'd double check all your apis are enabled and that you're making sure the project and dataset IDs are aligned within the Python script and your bigquery interface.

from schedule-python-script-using-google-cloud.

nimsim avatar nimsim commented on May 28, 2024

from schedule-python-script-using-google-cloud.

nimsim avatar nimsim commented on May 28, 2024

Updated requirements.txt with the latest package, but no go :(

from schedule-python-script-using-google-cloud.

sungchun12 avatar sungchun12 commented on May 28, 2024

The script calls to the api token from socrata.

Looking at the error code in more detail, it definitely has to do with the pandas gbq package and access issues to bigquery.

Try opening up the "append_data" script in a datalab notebook and run it manually to see if it breaks.

Send me a screenshot of your append_data code. I have a hunch the parameters are entered incorrectly.

from schedule-python-script-using-google-cloud.

nimsim avatar nimsim commented on May 28, 2024

Thanks for looking into it, append_data below.

Trying datalab later tonight

#this script appends live Chicago traffic data into BigQuery, there will be duplicates
#but that's accounted for with a saved view removing duplicates using SQL

from __future__ import print_function, absolute_import #package to smooth over python 2 and 3 differences
import pandas as pd #package for dataframes
from sodapy import Socrata #package for open source api
from google.datalab import Context #package for datalab
import time
from datetime import datetime, timedelta
import logging #package for error logging

#tracks error messaging
logging.basicConfig(level=logging.INFO)

# Unauthenticated client only works with public data sets. Note 'None'
# in place of application token, and no username or password:
#client = Socrata("data.cityofchicago.org", None)

#indent the run function by 1 tab
def run():
# Example authenticated client (needed for non-public datasets):
	client = Socraa("data.cityofchicago.org", "tokenremoved")
	                 
	# First 2000 results, returned as JSON from API / converted to Python list of
	# dictionaries by sodapy.
	results = client.get("8v9j-bter", limit=2000)
	
	# Convert to pandas DataFrame
	results_df = pd.DataFrame.from_records(results)
	
	
	#have this go directly into bigquery syntax-https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_gbq.html
	results_df.to_gbq('chicago_traffic.demo_data', "demo-nim", chunksize=2000, verbose=True, if_exists='append')

from schedule-python-script-using-google-cloud.

sungchun12 avatar sungchun12 commented on May 28, 2024

did you create a dataset id named "chicago_traffic" and an empty table named "demo_data"?

from schedule-python-script-using-google-cloud.

nimsim avatar nimsim commented on May 28, 2024

I didn't create demo_data. I read it as it would create one itself if it didn't exist. Also instructions only mention creating the dataset ID.

You need to have at least one field in an empty table, did you plot in all fields expected from the stream?
Edit: Ignore what I wrote above, that's not needed :)

from schedule-python-script-using-google-cloud.

nimsim avatar nimsim commented on May 28, 2024

Tried to set up a new project and going through the setup again, this time with demo_data.
No go. I'm actually gonna focus on doing Cloud Functions Get method to PubSub and from PubSub to BigQuery. Then I won't have to deal with app engine at all. Hopefully it'll work :)

Thanks for the help, and sorry for asking so many questions.

from schedule-python-script-using-google-cloud.

sungchun12 avatar sungchun12 commented on May 28, 2024

My mistake on creating the demo_data table. You shouldn't have to. Some weird access issue must be going on/the latest packages aren't correct in the requirements.txt file. So strange that it's not working as mine is working just fine.

If you need more help, feel free to ask! No need to apologize 😃

Would love to see your cloud functions demo when it's finished! I saw a couple medium blogs about it.

from schedule-python-script-using-google-cloud.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.