cant get around error expected an indented block in python jupyter lab

0 votes
import twitter

CONSUMER_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
CONSUMER_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
OAUTH_TOKEN = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
OAUTH_TOKEN_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

auth = twitter.oauth.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET,
twitter_api = twitter.Twitter(auth=auth)
# Nothing to see by displaying twitter_api except that it's now a
# defined variable
print (twitter_api)

# The Yahoo! Where On Earth ID for the entire world is 1.
# See and
US_WOE_ID = 23424977
# Prefix ID with the underscore for query string parameterization.
# Without the underscore, the twitter package appends the ID value
# to the URL itself as a special case keyword argument.
world_trends =
us_trends =
print (world_trends)
print (us_trends)

import json
print (json.dumps)(world_trends, indent=1)
print (json.dumps)(us_trends, indent=1)

world_trends_set = set([trend['name']
for trend in world_trends[0]['trends']])
us_trends_set = set([trend['name']
for trend in us_trends[0]['trends']])
common_trends = world_trends_set.intersection(us_trends_set)
print (common_trends)

# XXX: Set this variable to a trending topic,
# or anything else for that matter. The example query below
# was a trending topic when this content was being developed
# and is used throughout the remainder of this chapter.
q = '#MentionSomeoneImportantForYou'
count = 100
# See
search_results =, count=count)
statuses = search_results['statuses']
# Iterate through 5 more batches of results by following the cursor

for _ in range(5):
print "Length of statuses", len(statuses)
next_results = search_results['search_metadata']['next_results']
except KeyError, e: # No more results when next_results doesn't exist
# Create a dictionary from next_results, which has the following form:
# ?max_id=313519052523986943&q=NCAA&include_entities=1
kwargs = dict([ kv.split('=') for kv in next_results[1:].split("&") ])
search_results =**kwargs)
statuses += search_results['statuses']
# Show one sample search result by slicing the list...
Nov 18, 2020 in Data Analytics by David
• 120 points

edited Nov 19, 2020 by MD 98 views

Hey, @David,

The most recent python IDEs support converting the tab to space and space to tabs. Stick to whatever format you want to use. This is going to solve the error. Check the option in your python IDE to convert the tab to space and convert the tab to space or the tab to space to correct the error.

1 answer to this question.

0 votes

First thing, don't share your credentials with anyone. Somebody may misuse your Twitter account. And you are getting this error because you did not indent your for loop properly. So check your code and indent properly. It will work.
answered Nov 19, 2020 by MD
• 95,140 points

Related Questions In Data Analytics

0 votes
1 answer

Error saying expected symbol in R

Write the code in the following way: myfunction ...READ MORE

answered Nov 9, 2018 in Data Analytics by Maverick
• 10,840 points
0 votes
1 answer

Error saying "Failed to get an access token." when trying to access my Google Analytics API

Try this: library(RGoogleAnalytics) oauth_token <- Auth( = ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,840 points
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,983 views
0 votes
0 answers
0 votes
1 answer