Skip to content

Commit

Permalink
Merge pull request #151 from nightzeroeth/main
Browse files Browse the repository at this point in the history
Bug fix in recent_tweet_counts.py
  • Loading branch information
sparack authored Mar 11, 2024
2 parents 47cb8c5 + 22376e8 commit 8c63446
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Recent-Tweet-Counts/recent_tweet_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def bearer_oauth(r):


def connect_to_endpoint(url, params):
response = requests.request("GET", search_url, auth=bearer_oauth, params=params)
response = requests.request("GET", url, auth=bearer_oauth, params=params)
print(response.status_code)
if response.status_code != 200:
raise Exception(response.status_code, response.text)
Expand All @@ -36,4 +36,4 @@ def main():


if __name__ == "__main__":
main()
main()

2 comments on commit 8c63446

@fochoao-alt
Copy link

@fochoao-alt fochoao-alt commented on 8c63446 Dec 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import requests

def safe_get_request(url, params):
   # Ensure params are properly sanitized
   sanitized_params = {k: str(v).replace('<', '&lt;').replace('>', '&gt;') for k, v in params.items()}
   
   response = requests.get(url, params=sanitized_params)
   
   if response.status_code != 200:
       raise Exception(response.status_code, response.text)
   
   return response

# Example usage
url = 'https://example.com/api'
params = {
   'query': 'safe input'
}

response = safe_get_request(url, params)
print(response.text)

@fochoao-alt
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safer so as to avoid SQL injection and Cross-side scripting.

Please sign in to comment.