I am getting Expected Ptr<cv::UMat> for argument 'src' error while running ocr python file. Below attached is the full error message - ocr

it is working fine in my local system but when running from pythonanywhere.com, i am getting this error.
Traceback (most recent call last):
File "/home/clonesangram/.virtualenvs/django3/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/home/clonesangram/.virtualenvs/django3/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/clonesangram/django_projects/ocrsite/ocr/views.py", line 187, in image_upload_view
return render(request, 'ocr/index1.html', {'form': form, 'img_obj': img_obj, 'text': text_detector(image)})
File "/home/clonesangram/django_projects/ocrsite/ocr/Test_OCR_Img.py", line 15, in text_detector
image = cv2.resize(np.float32(image), (320, 320), interpolation=cv2.INTER_AREA)
Exception Type: TypeError at /ocr/upload/
Exception Value: Expected Ptr<cv::UMat> for argument 'src'

Related

Connection refused when switching TPU version

How can I switch TPU version for TPU VM architechture?
When attempting to switch software version for TPU(TPU VM architechture switching from tpu-vm-tf-2.6.0-pod to tpu-vm-base) using instructions found here, I get Connection Refused exception with traceback:
Traceback (most recent call last):
File "/usr/lib/python3.8/urllib/request.py", line 1354, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
File "/usr/lib/python3.8/http/client.py", line 1256, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1302, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1251, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1011, in _send_output
self.send(msg)
File "/usr/lib/python3.8/http/client.py", line 951, in send
self.connect()
File "/usr/lib/python3.8/http/client.py", line 922, in connect
self.sock = self._create_connection(
File "/usr/lib/python3.8/socket.py", line 808, in create_connection
raise err
File "/usr/lib/python3.8/socket.py", line 796, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "switch.py", line 20, in <module>
c.configure_tpu_version(args.target_version, restart_type="ifNeeded")
File "/usr/local/lib/python3.8/dist-packages/cloud_tpu_client/client.py", line 391, in configure_tpu_version
for result in results:
File "/usr/lib/python3.8/concurrent/futures/_base.py", line 619, in result_iterator
yield fs.pop().result()
File "/usr/lib/python3.8/concurrent/futures/_base.py", line 444, in result
return self.__get_result()
File "/usr/lib/python3.8/concurrent/futures/_base.py", line 389, in __get_result
raise self._exception
File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.8/dist-packages/cloud_tpu_client/client.py", line 375, in configure_worker
request.urlopen(req)
File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.8/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/usr/lib/python3.8/urllib/request.py", line 542, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/usr/lib/python3.8/urllib/request.py", line 1383, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "/usr/lib/python3.8/urllib/request.py", line 1357, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 111] Connection refused>
The command is run on cloud TPU VM with cloud-tpu-client version 0.10
When running the same command from my PC I get Connection timed out after a long pause with traceback:
Traceback (most recent call last):
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/urllib/request.py", line 1350, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/http/client.py", line 1281, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/http/client.py", line 1327, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/http/client.py", line 1276, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/http/client.py", line 1036, in _send_output
self.send(msg)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/http/client.py", line 976, in send
self.connect()
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/http/client.py", line 948, in connect
(self.host,self.port), self.timeout, self.source_address)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/socket.py", line 728, in create_connection
raise err
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/socket.py", line 716, in create_connection
sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "tpu_version.py", line 19, in <module>
c.configure_tpu_version(args.target_version, restart_type="ifNeeded")
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/site-packages/cloud_tpu_client/client.py", line 392, in configure_tpu_version
for result in results:
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/concurrent/futures/_base.py", line 598, in result_iterator
yield fs.pop().result()
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/concurrent/futures/_base.py", line 435, in result
return self.__get_result()
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
raise self._exception
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/site-packages/cloud_tpu_client/client.py", line 376, in configure_worker
request.urlopen(req)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/urllib/request.py", line 543, in _open
'_open', req)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/urllib/request.py", line 503, in _call_chain
result = func(*args)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/urllib/request.py", line 1378, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "/home/nevus/anaconda3/envs/imageGen/lib/python3.7/urllib/request.py", line 1352, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 110] Connection timed out>
This feature is not supported by the TPU VM architecture.
Best way to change the TPU VM's version would be to delete it and recreate a new one with the desired version.

Unable to send json request when using fastapi

I have error in the following code when I try to send a request with json data in it, is it because it only works synchronously, so does not work in fastapi which work asynchronously? If that is the case, what is the simplest way to send a request with json data in it?
import time
from fastapi import Request, FastAPI, BackgroundTasks
import multiprocessing as mp
import uvicorn
import requests
import json
def printmessage(job):
time.sleep(5)
print(job)
if __name__ == 'webhook_fastapi':
url = 'http://127.0.0.1:8000/webhook'
data = { 'text': 'hello'}
r = requests.post(url, data=json.dumps(data), headers={'Content-Type': 'application/json'})
print("Request Sent!")
app = FastAPI()
#app.post("/webhook")
async def webhook(request : Request, background_tasks: BackgroundTasks):
print("WEBHOOK RECEIVED")
job="doctor"
background_tasks.add_task(printmessage,job)
print('done')
return 'WEBHOOK RECEIVED'
if __name__ == '__main__':
print("PROGRAM LAUNCH...")
print("WEBHOOK RECEIVE READY...")
background_tasks = BackgroundTasks()
job="doctor"
background_tasks.add_task(printmessage,job)
uvicorn.run("webhook_fastapi:app", reload=False)
OUTPUT:
__main__
PROGRAM LAUNCH...
WEBHOOK RECEIVE READY...
webhook_fastapi
Traceback (most recent call last): File
"C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py",
line 169, in _new_conn
conn = connection.create_connection( File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\connection.py",
line 96, in create_connection
raise err File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\connection.py",
line 86, in create_connection
sock.connect(sa) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused
it
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py",
line 699, in urlopen
httplib_response = self._make_request( File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py",
line 394, in _make_request
conn.request(method, url, **httplib_request_kw) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py",
line 234, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers) File
"C:\Users\User\AppData\Local\Programs\Python\Python39\lib\http\client.py",
line 1279, in request
self._send_request(method, url, body, headers, encode_chunked) File
"C:\Users\User\AppData\Local\Programs\Python\Python39\lib\http\client.py",
line 1325, in _send_request
self.endheaders(body, encode_chunked=encode_chunked) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\http\client.py",
line 1274, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked) File
"C:\Users\User\AppData\Local\Programs\Python\Python39\lib\http\client.py",
line 1034, in _send_output
self.send(msg) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\http\client.py",
line 974, in send
self.connect() File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py",
line 200, in connect
conn = self._new_conn() File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py",
line 181, in _new_conn
raise NewConnectionError( urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x0000013C0E494310>:
Failed to establish a new connection: [WinError 10061] No connection
could be made because the target machine actively refused it
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\adapters.py",
line 439, in send
resp = conn.urlopen( File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py",
line 755, in urlopen
retries = retries.increment( File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\retry.py",
line 574, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1',
port=8000): Max retries exceeded with url: /webhook (Caused by
NewConnectionError('<urllib3.connection.HTTPConnection object at
0x0000013C0E494310>: Failed to establish a new connection: [WinError
10061] No connection could be made because the target machine actively
refused it'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"c:\Users*\webhook_fastapi.py", line 40, in
uvicorn.run("webhook_fastapi:app", reload=False) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\uvicorn\main.py",
line 463, in run
server.run() File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\uvicorn\server.py",
line 60, in run
return asyncio.run(self.serve(sockets=sockets)) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\asyncio\runners.py",
line 44, in run
return loop.run_until_complete(main) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py",
line 642, in run_until_complete
return future.result() File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\uvicorn\server.py",
line 67, in serve
config.load() File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\uvicorn\config.py",
line 458, in load
self.loaded_app = import_from_string(self.app) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\uvicorn\importer.py",
line 21, in import_from_string
module = importlib.import_module(module_str) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\importlib_init_.py",
line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File
"", line 1007, in _find_and_load File
"", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "", line 850, in
exec_module File "", line 228, in
_call_with_frames_removed File "c:\Users*\webhook_fastapi.py", line 19, in
r = requests.post(url, data=json.dumps(data), headers={'Content-Type': 'application/json'}) File
"C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py",
line 117, in post
return request('post', url, data=data, json=json, **kwargs) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py",
line 61, in request
return session.request(method=method, url=url, **kwargs) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py",
line 542, in request
resp = self.send(prep, **send_kwargs) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py",
line 655, in send
r = adapter.send(request, kwargs) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\adapters.py",
line 516, in send
raise ConnectionError(e, request=request) requests.exceptions.ConnectionError:
HTTPConnectionPool(host='127.0.0.1', port=8000): Max retries exceeded
with url: /webhook (Caused by
NewConnectionError('<urllib3.connection.HTTPConnection object at
0x0000013C0E494310>: Failed to establish a new connection: [WinError
10061] No connection could be made because the target machine actively
refused it')) PS C:\Users*>
There is no server running when you're trying to make your request. uvicorn is importing your code, and you're apparently trying to make a request while the code is being imported.
uvicorn can't launch the API and bind to the port before it has finished importing the code and the ASGI application has been set up and properly configured.

ValueError: No JSON object could be decoded building Chromium

When building chromium with this
autoninja -C out/Debug chrome
I get this errors:
[915/51478] ACTION //components/resources:about_credits(//build/toolchain/win:win_clang_x86)
FAILED: gen/components/resources/about_credits.html
C:/Users/duyvk/chromium/depot_tools/bootstrap-2#3_8_10_chromium_23_bin/python/bin/python.exe ../../tools/licenses.py --target-os=win --depfile gen/components/resources/about_credits.d credits gen/components/resources/about_credits.html
Traceback (most recent call last):
File "../../tools/licenses.py", line 870, in <module>
sys.exit(main())
File "../../tools/licenses.py", line 855, in main
args.depfile):
File "../../tools/licenses.py", line 693, in GenerateCredits
extra_third_party_dirs)
File "../../tools/licenses.py", line 533, in FindThirdPartyDirs
ProcessAdditionalReadmePathsJson(root, dirpath, third_party_dirs)
File "../../tools/licenses.py", line 504, in ProcessAdditionalReadmePathsJson
extra_paths = json.load(paths_file)
File "C:\Users\duyvk\chromium\depot_tools\bootstrap-2#3_8_10_chromium_23_bin\python\bin\lib\json\__init__.py", line 291, in load
**kw)
File "C:\Users\duyvk\chromium\depot_tools\bootstrap-2#3_8_10_chromium_23_bin\python\bin\lib\json\__init__.py", line 339, in loads
return _default_decoder.decode(s)
File "C:\Users\duyvk\chromium\depot_tools\bootstrap-2#3_8_10_chromium_23_bin\python\bin\lib\json\decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\duyvk\chromium\depot_tools\bootstrap-2#3_8_10_chromium_23_bin\python\bin\lib\json\decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
[932/51478] ACTION //third_party/blink/renderer/bindings:generate_bindings_all(//build/toolchain/win:win_clang_x86)
ninja: build stopped: subcommand failed
I have done some googling but I can't find any solutions.
I'm using Visual Studio 19.

Django + SSL + mysql: TypeError: __init__() got an unexpected keyword argument 'server_hostname'

I used Djano to build a simple restful API server. SSL has been introduced to the communication between the server and the remote database to enforce security. When the API server tried to write to the database, I got the following error:
File "/app/anaconda/lib/python2.7/site-packages/django/core/handlers/exception.py", line 39, in inner
response = get_response(request)
File "/app/anaconda/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/app/anaconda/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/app/anaconda/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/app/anaconda/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/app/anaconda/lib/python2.7/site-packages/rest_framework/views.py", line 474, in dispatch
response = self.handle_exception(exc)
File "/app/anaconda/lib/python2.7/site-packages/rest_framework/views.py", line 434, in handle_exception
self.raise_uncaught_exception(exc)
File "/app/anaconda/lib/python2.7/site-packages/rest_framework/views.py", line 471, in dispatch
response = handler(request, *args, **kwargs)
File "/app/anaconda/lib/python2.7/site-packages/rest_framework/decorators.py", line 52, in handler
return func(*args, **kwargs)
File "/app/mobile/mpq_backup_response/mpq_backup_response/backup_response/views.py", line 39, in sms
q.save()
File "/app/anaconda/lib/python2.7/site-packages/django/db/models/base.py", line 796, in save
force_update=force_update, update_fields=update_fields)
File "/app/anaconda/lib/python2.7/site-packages/django/db/models/base.py", line 821, in save_base
with transaction.atomic(using=using, savepoint=False):
File "/app/anaconda/lib/python2.7/site-packages/django/db/transaction.py", line 158, in __enter__
if not connection.get_autocommit():
File "/app/anaconda/lib/python2.7/site-packages/django/db/backends/base/base.py", line 365, in get_autocommit
self.ensure_connection()
File "/app/anaconda/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
self.connect()
File "/app/anaconda/lib/python2.7/site-packages/django/db/backends/base/base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "/app/anaconda/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 265, in get_new_connection
conn = Database.connect(**conn_params)
File "/app/anaconda/lib/python2.7/site-packages/pymysql/__init__.py", line 90, in Connect
return Connection(*args, **kwargs)
File "/app/anaconda/lib/python2.7/site-packages/pymysql/connections.py", line 688, in __init__
self.connect()
File "/app/anaconda/lib/python2.7/site-packages/pymysql/connections.py", line 906, in connect
self._request_authentication()
File "/app/anaconda/lib/python2.7/site-packages/pymysql/connections.py", line 1086, in _request_authentication
self._sock = self.ctx.wrap_socket(self._sock, server_hostname=self.host)
File "/app/anaconda/lib/python2.7/ssl.py", line 352, in wrap_socket
_context=self)
TypeError: __init__() got an unexpected keyword argument 'server_hostname'
However, if I went into Djangon's shell interactive environment and wrote directly into the database, everything went smoothly. I don't why this problem happens.
This issue seems to exist in OS X with python 2.7.10 and according to the link below, you will most likely run into this with CentOS 7 and Python ver 2.7.9 or above.
https://github.com/gevent/gevent/issues/477
Updating gevent to 1.2.1 seems to solve the problem.
You could run "pip install --upgrade gevent" on mac to fix this.

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot focus element

I wanna scrape the site.
When I executed my code I got a problem.
Here is my code.
class good_auction(object):
def __init__(self):
self.driverPath = r"D:\python code\NaverBlogCralwer\NaverBlogCralwer\chromedriver.exe"
self.driver = webdriver.Chrome(self.driverPath)
def main_scrape(self):
self.driver.get('http://www.goodauction.com/index.php')
time.sleep(5)
self.driver.find_element_by_name('client_id').send_keys("myid")
self.driver.find_element_by_id("pwd_dummy").send_keys('mypassword')
if __name__ == '__main__':
scraper = good_auction()
scraper.main_scrape()
and I got this error
Traceback (most recent call last):
File "D:/python code/auction_crawl/auction_crawler.py", line 36, in <module>
scraper.main_scrape()
File "D:/python code/auction_crawl/auction_crawler.py", line 27, in main_scrape
self.driver.find_element_by_id("pwd_dummy").send_keys('k1150719!!!')
File "C:\Users\Hyun Mo\Anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 347, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': keys_to_typing(value)})
File "C:\Users\Hyun Mo\Anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 491, in _execute
return self._parent.execute(command, params)
File "C:\Users\Hyun Mo\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 238, in execute
self.error_handler.check_response(response)
File "C:\Users\Hyun Mo\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 193, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot focus element
(Session info: chrome=56.0.2924.87)
(Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 10.0.14393 x86_64)
How can I fix it??
Will I change my driver?? or Will I search for execute_script?? But I don't know javascript
I solve this problems.
password = self.driver.find_element_by_id("pwd_dummy")
actions = webdriver.ActionChains(self.driver)
actions.move_to_element(password)
actions.click()
actions.send_keys("mypassword") # Replace with whichever keys you want.
actions.perform()
I use above code instead of below code.
self.driver.find_element_by_id("pwd_dummy").clear()
self.driver.find_element_by_id("pwd_dummy").send_keys('mypassword')