Using searchtweets API, twitter api keeps returning 422 error


I am trying to retrieve historical data using Searchtweets API but I keep getting twitter 422 error. Weird thing is, before this code I had a previous code where it had worked perfectly. But after this, the old code doesn’t work either

I have followed the documentation, double checked that I have full archive access and even regenerated my tokens and access keys.

This is my python code :

import json
import csv

from searchtweets import collect_results, load_credentials, gen_rule_payload

enterprise_search_args = load_credentials(“twitter_keys.yaml”, yaml_key = “search_tweets_api”, env_overwrite = False)

from_date = “2016-06-01”
to_date = “2016-06-23”

with open(‘map_data/london_borough.csv’, ‘r’, newline = “”) as csvFile:
boroughs = list(csv.reader(csvFile, delimiter = ‘,’))
for num, borough in enumerate(boroughs):
if num:
name = boroughs[0]
box_coord = borough[5]
if box_coord:
box_coord = ‘[’+box_coord.replace(’,’,’ ‘)+’]’
rule = gen_rule_payload(“brexit”, results_per_call = 100, from_date = from_date, to_date = to_date)
rule = json.loads(rule)
rule[‘bounding_box’] = box_coord
rule = json.dumps(rule)
tweets = collect_results(rule, max_results = 500, result_stream_args = enterprise_search_args)
with open(’%s.csv’%(name), ‘w’, newline = “”) as writeFile:
for tweet in tweets:
writeFile.write(’%s, %s, %s\n’%(, tweet.created_at_string, tweet.all_text))

And my YAML file:

account_type: premium
consumer_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
consumer_secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Upon running the above code, I get this on the console:

Grabbing bearer token from OAUTH
[-0.105400 51.507354 -0.074673 51.521028]
{“query”: “brexit”, “maxResults”: 100, “toDate”: “201606230000”, “fromDate”: “201606010000”, “bounding_box”: “[-0.105400 51.507354 -0.074673 51.521028]”}
retrying request; current status code: 422
retrying request; current status code: 422

Does anyone know of a solution to this or where i may be going wrong? Any help will be greatly appreciated!