Bug:
There is no current event loop in thread 'Thread-1'. while i fetch view count from video using tiktok api
Code:
from flask import request, Flask, jsonify
from flask_cors import CORS
from flask_restful import Resource, Api
from TikTokApi import TikTokApi
app = Flask(name)
api = Api(app)
cors = CORS(app)
tikTokApi = TikTokApi()
class test(Resource):
def post(self):
return 'TIKTOK API IS Running'
class twitterviewcount(Resource):
def post(self):
if request.method == 'POST':
if 'URL' not in request.json:
return 'No request URL found!'
data = request.json
HASHTAG = data["hashtag"]
URL = data["URL"]
video = tikTokApi.video(url=URL)
video_views = video.as_dict['stats']['playCount']
hashtag_detected = HASHTAG in video.as_dict['desc']
res = {}
res['Hashtag'] = hashtag_detected
res['view'] = video_views
print(HASHTAG),
return jsonify(res)
class twitterfollowercount(Resource):
def post(self):
if request.method == 'POST':
if 'URL' not in request.json:
return 'No request URL found!'
data = request.json
data = request.json
URL = data["URL"]
video = tikTokApi.video(url=URL)
user_id = video.as_dict['author']['id']
user = api.user(user_id)
user_followers = user.info_full()['stats']['followerCount']
res = {}
res['Follower'] = user_followers
return jsonify(res)
if name == 'main':
app.run(host='0.0.0.0',debug=True, threaded=False)
**Expected behavior**
A need a view count from tiktok video URL
Error:
<textarea cols="50" rows="10" name="code" readonly>Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2095, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2080, in wsgi_app
response = self.handle_exception(e)
File "/usr/local/lib/python3.8/dist-packages/flask_cors/extension.py", line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/usr/local/lib/python3.8/dist-packages/flask_restful/__init__.py", line 271, in error_router
return original_handler(e)
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2077, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1525, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.8/dist-packages/flask_cors/extension.py", line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/usr/local/lib/python3.8/dist-packages/flask_restful/__init__.py", line 271, in error_router
return original_handler(e)
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1523, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1509, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/usr/local/lib/python3.8/dist-packages/flask_restful/__init__.py", line 467, in wrapper
resp = resource(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/flask/views.py", line 84, in view
return current_app.ensure_sync(self.dispatch_request)(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/flask_restful/__init__.py", line 582, in dispatch_request
resp = meth(*args, **kwargs)
File "/main.py", line 27, in post
video_views = video.as_dict['stats']['playCount']
File "/usr/local/lib/python3.8/dist-packages/TikTokApi/api/video.py", line 145, in __getattr__
self.as_dict = self.info()
File "/usr/local/lib/python3.8/dist-packages/TikTokApi/api/video.py", line 70, in info
return self.info_full(**kwargs)["itemInfo"]["itemStruct"]
File "/usr/local/lib/python3.8/dist-packages/TikTokApi/api/video.py", line 92, in info_full
return self.parent.get_data(path, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/TikTokApi/tiktok.py", line 224, in get_data
) = asyncio.get_event_loop().run_until_complete(
File "/usr/lib/python3.8/asyncio/events.py", line 639, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-1'.
</textarea>
Bug: There is no current event loop in thread 'Thread-1'. while i fetch view count from video using tiktok api
Code:
from flask import request, Flask, jsonify from flask_cors import CORS from flask_restful import Resource, Api from TikTokApi import TikTokApi app = Flask(name) api = Api(app) cors = CORS(app) tikTokApi = TikTokApi()
@app.errorhandler(404) def page_not_found(e): return {'status': 'fail'}, 404
class test(Resource): def post(self): return 'TIKTOK API IS Running'
class twitterviewcount(Resource): def post(self): if request.method == 'POST': if 'URL' not in request.json: return 'No request URL found!' data = request.json HASHTAG = data["hashtag"] URL = data["URL"] video = tikTokApi.video(url=URL) video_views = video.as_dict['stats']['playCount'] hashtag_detected = HASHTAG in video.as_dict['desc'] res = {} res['Hashtag'] = hashtag_detected res['view'] = video_views print(HASHTAG), return jsonify(res)
class twitterfollowercount(Resource): def post(self): if request.method == 'POST': if 'URL' not in request.json: return 'No request URL found!' data = request.json data = request.json URL = data["URL"] video = tikTokApi.video(url=URL) user_id = video.as_dict['author']['id'] user = api.user(user_id) user_followers = user.info_full()['stats']['followerCount'] res = {} res['Follower'] = user_followers return jsonify(res)
api.add_resource(test, '/') api.add_resource(twitterviewcount, '/tiktokview') api.add_resource(twitterfollowercount, '/tiktokfollower')
if name == 'main': app.run(host='0.0.0.0',debug=True, threaded=False)
**Desktop