llk010502 commited on
Commit
59ee4f8
1 Parent(s): 0f0f25e

debug requests error

Browse files
Files changed (2) hide show
  1. .DS_Store +0 -0
  2. app.py +9 -1
.DS_Store ADDED
Binary file (6.15 kB). View file
 
app.py CHANGED
@@ -112,7 +112,15 @@ def stock_news_em(symbol: str = "300059", page = 1) -> pd.DataFrame:
112
  + ',"type":["cmsArticleWebOld"],"client":"web","clientType":"web","clientVersion":"curr","param":{"cmsArticleWebOld":{"searchScope":"default","sort":"default",' + f'"pageIndex":{page}'+ ',"pageSize":100,"preTag":"<em>","postTag":"</em>"}}}',
113
  "_": "1668256937996",
114
  }
115
- r = requests.get(url, params=params)
 
 
 
 
 
 
 
 
116
  data_text = r.text
117
  data_json = json.loads(
118
  data_text.strip("jQuery3510875346244069884_1668256937995(")[:-1]
 
112
  + ',"type":["cmsArticleWebOld"],"client":"web","clientType":"web","clientVersion":"curr","param":{"cmsArticleWebOld":{"searchScope":"default","sort":"default",' + f'"pageIndex":{page}'+ ',"pageSize":100,"preTag":"<em>","postTag":"</em>"}}}',
113
  "_": "1668256937996",
114
  }
115
+ try:
116
+ r = requests.get(url, params=params, timeout=30)
117
+ except requests.exceptions.ReadTimeout:
118
+ print("The request timed out. Trying again...")
119
+ # Retry the request or handle the timeout in other ways
120
+ except requests.exceptions.RequestException as e:
121
+ # Handle other potential exceptions
122
+ print(f"An error occurred: {e}")
123
+
124
  data_text = r.text
125
  data_json = json.loads(
126
  data_text.strip("jQuery3510875346244069884_1668256937995(")[:-1]