I am trying to log the pyodbc exception to a log file, the problem is, using the standard python logging, the code produces another exception related to encoding some unidentified characters (looks like Chines) that appears in the exception args, the exception stack trace:
Exception: [23000] [Oracle][ODBC][Ora]ORA-00001: unique constraint
(REDWOOD.TITLE_PK) violated ORA-06512: at line 53 ઊȯ 诔唱 㸸ੌȯ s ઉȯ
㸸ੌȯ ꦓ倗翸 ᴘඇȯ 㫏杦翸 ɘઊȯ 텈ઉȯ 㸸ੌȯ 糆倘翸 ! H
촼杧翸 (1) (SQLExecDirectW)
--- Logging error --- Traceback (most recent call last): File "\Transfer\transfer\transfer_records.py", line 123, in transfer_record
row.PUBSTAT, row.CITED) File "\Transfer\transfer\db_access.py", line 476, in transfer_record
self.cursor.execute(sql_block, params)
pyodbc.IntegrityError: ('23000', '[23000]
[Oracle][ODBC][Ora]ORA-00001: unique constraint (REDWOOD.TITLE_PK)
violated\nORA-06512: at line
53\n\x00ઊȯ\x00诔唱\x00\x00㸸ੌȯ\x00\x00\x00s\x00\uec40ઉȯ\x00\x00\uf600\x00\x00㸸ੌȯ\x00ꦓ倗翸\x00ᴘඇȯ\x00㫏杦翸\x00ɘઊȯ\x00텈ઉȯ\x00㸸ੌȯ\x00糆倘翸\x00\x00\x00\x01\x00!\x00\x00\x00H\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00촼杧翸\x00
(1) (SQLExecDirectW)')
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Python\lib\logging__init__.py", line 994, in emit
stream.write(msg) File "C:\Python\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode characters in
position 167-168: character maps to Call stack: File
"/Transfer/trans_ui.py", line 162, in
app.mainloop() File "C:\Python\lib\tkinter__init__.py", line 1277, in mainloop
self.tk.mainloop(n) File "C:\Python\lib\tkinter__init__.py", line 1699, in call
return self.func(*args) File "/Transfer/trans_ui.py", line 130, in transfer_records
start_transfer.main(options=options, app=self) File "\Transfer\start_transfer.py", line 19, in main
transfer.start() File "Transfer\transfer\transfer_records.py", line 46, in start
list(map(self.transfer_record, self.transfer_rows)) File "Transfer\transfer\transfer_records.py", line 145, in transfer_record
logging.error("Exception details: " + ex.args[1]) Message: 'Exception details: [23000] [Oracle][ODBC][Ora]ORA-00001: unique
constraint (THOTH.TITLE_PK) violated\nORA-06512: at line
53\n\x00ઊȯ\x00诔唱\x00\x00㸸ੌȯ\x00\x00\x00s\x00\uec40ઉȯ\x00\x00\uf600\x00\x00㸸ੌȯ\x00ꦓ倗翸\x00ᴘඇȯ\x00㫏杦翸\x00ɘઊȯ\x00텈ઉȯ\x00㸸ੌȯ\x00糆倘翸\x00\x00\x00\x01\x00!\x00\x00\x00H\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00촼杧翸\x00
(1) (SQLExecDirectW)' Arguments: () Total Time: 24.116901397705078
Process finished with exit code 0
The Exception handler that produces the exception:
except pyodbc.Error as ex:
print("Exception: ", ex.args[1])
self.database.rollback()
self.records_counter['transfer_errors'] += 1
logging.error("Exception details: " + ex.args[1])
self.status_update("An Exception Occurred while transferring
record: " + row.CTRLNO + "-" + row.LEVL + " Details:" +
ex.args[1], msgbox='Error')
What are these characters that appears as part of the exception args?
How I can get rid of them as it seems they are producing the encoding exception
You can get rid of them by encoding explicitly so that you can use errors="replace" or ignore The resulting bytes will not be pretty but they will be logged.
logging.error("Exception: " + str(ex.args[1].encode(encoding='charmap', errors='replace')))
Related
When computing with Python Cado on multiple servers but I got:
--- Logging error ---
Traceback (most recent call last):
File "/share/home/ybpan/local/lib/cado-nfs-3.0.0/scripts/cadofactor/cadotask.py", line 4888, in run
message = self.submit_command(p, None, log_errors=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/share/home/ybpan/local/lib/cado-nfs-3.0.0/scripts/cadofactor/cadotask.py", line 1386, in submit_command
process = cadocommand.Command(command)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/share/home/ybpan/local/lib/cado-nfs-3.0.0/scripts/cadofactor/cadocommand.py", line 81, in __init__
stdout.filter(x.decode("utf-8"))
File "/share/home/ybpan/local/lib/cado-nfs-3.0.0/scripts/cadofactor/cadotask.py", line 4538, in filter
super().filter(data)
File "/share/home/ybpan/local/lib/cado-nfs-3.0.0/scripts/cadofactor/cadotask.py", line 1028, in filter
self.stdout.write(data)
OSError: [Errno 28] No space left on device
During handling of the above exception, another exception occurred:
OSError: [Errno 28] No space left on device
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/share/home/ybpan/local/lib/cado-nfs-3.0.0/scripts/cadofactor/cadotask.py", line 6297, in run
last_status = task.run()
^^^^^^^^^^
File "/share/home/ybpan/local/lib/cado-nfs-3.0.0/scripts/cadofactor/cadotask.py", line 4882, in run
with bwc_output_filter(self.logger, str(stdoutpath)) as outfilter:
File "/share/home/ybpan/local/lib/cado-nfs-3.0.0/scripts/cadofactor/cadotask.py", line 1032, in __exit__
self.stdout.close()
OSError: [Errno 28] No space left on device
During handling of the above exception, another exception occurred:
... ...
Which implies I had No space left on device, but actually I got enough space on multiple servers;
Thanks for any instructions!
The memory has 100g space but the errors still occured;
wondering if anyone can help me figure out why I am not catching the TimeExhausted exception when using
wait_for_transaction_receipt()
from web3.py
I want the error to be thrown after waiting 45 seconds, I want to catch the error, then go do some other stuff, and wait again. I want to repeat this cycle until the transaction is mined & then exit / break. I think it's a simple syntax issue but not sure -- last time the exception was raised, my code didn't catch it, and instead it lead to an AttributeError
here's my code:
from web3 import Web3
while True:
try:
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash, timeout=45)
print(f"{str(dt.utcnow())[:-7]} | Transaction receipt: {tx_receipt}")
break
except Web3.TimeExhausted as e:
print(f"{str(dt.utcnow())[:-7]} | A Inner exception caught: {e}.")
print(
f"{str(dt.utcnow())[:-7]} | Timed out waiting for transaction. "
+ f"Will update SMA & wait again..."
)
update_sma_data()
pass
Finally here is my error text:
Traceback (most recent call last):
File "/home/flim/.local/lib/python3.8/site-packages/web3/eth.py", line 783, in wait_for_transaction_receipt
_timeout.sleep(poll_latency)
File "/home/flim/.local/lib/python3.8/site-packages/web3/_utils/threads.py", line 89, in sleep
self.check()
File "/home/flim/.local/lib/python3.8/site-packages/web3/_utils/threads.py", line 82, in check
raise self
web3._utils.threads.Timeout: 45 seconds
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "money-maker-mike.py", line 301, in sign_and_send_tx
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash, timeout=45)
File "/home/flim/.local/lib/python3.8/site-packages/web3/eth.py", line 787, in wait_for_transaction_receipt
raise TimeExhausted(
web3.exceptions.TimeExhausted: Transaction HexBytes('0xd60bc63a96b5b81b98ca39308fc9ab709d2f2ccfd1b03c064db285f954633d34') is not in the chain after 45 seconds
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "money-maker-mike.py", line 529, in <module>
main()
File "money-maker-mike.py", line 522, in main
trade()
File "money-maker-mike.py", line 373, in trade
zero_ex_trade(sell_token, buy_token, sell_amount)
File "money-maker-mike.py", line 278, in zero_ex_trade
sign_and_send_tx(tx)
File "money-maker-mike.py", line 306, in sign_and_send_tx
except Web3.TimeExhausted as e:
AttributeError: type object 'Web3' has no attribute 'TimeExhausted'
Thanks in advance :D
from web3.exceptions import TimeExhausted
try:
...
except TimeExhausted as e:
...
Source: web3.py/test_transactions.py at master · eric-s321/web3.py
I have two issues:
I'm calling G-Ads API to bulk remove ads (code)
for error_detail in error_details:
# Retrieve an instance of the google_ads_failure class from the client
failure_message = gAdsServiceWrapper.client.get_type("google_ads_failure")
# Parse the string into a google_ads_failure message instance.
# To access class-only methods on the message we retrieve its type.
google_ads_failure = type(failure_message)
failure_object = google_ads_failure.deserialize(error_detail.value)
for error in failure_object.errors:
# Construct and print a string that details which element in
# the above ad_group_operations list failed (by index number)
# as well as the error message and error code.
print("A partial failure at index "
f"{error.location.field_path_elements[0].index} occurred "
f"\nError message: {error.message}\nError code: "
f"{error.error_code}")
index_array.append(error.location.field_path_elements[0].index)
error_array.append({"error_message": error.message, "error_code": error.error_code})
I get a partial error
And the code fails to parse it (taken form the official website)
My terminal shows:
Partial failures occurred. Details will be shown below.
Traceback (most recent call last):
File "D:\projects\bowling\venv\lib\site-packages\google\ads\googleads\client.py", line 426, in get_type
message_class = getattr(type_classes, name)
File "D:\projects\bowling\venv\lib\site-packages\google\ads\googleads\v8\__init__.py", line 1753, in __getattr__
raise AttributeError(f"unknown type {name!r}.")
AttributeError: unknown type 'google_ads_failure'.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\projects\bowling\src\main.py", line 535, in <module>
main(args.top_id)
File "D:\projects\bowling\src\main.py", line 141, in main
removed_ads_count = remove_disapproved_ads_for_account(account)
File "D:\projects\bowling\src\main.py", line 206, in remove_disapproved_ads_for_account
remove_ads(ad_removal_operations, ads_to_remove_json, account_id)
File "D:\projects\bowling\src\main.py", line 300, in remove_ads
index_array, error_array = _print_results(response_chunk)
File "D:\projects\bowling\src\main.py", line 439, in _print_results
failure_message = gAdsServiceWrapper.client.get_type("google_ads_failure")
File "D:\projects\bowling\venv\lib\site-packages\google\ads\googleads\client.py", line 428, in get_type
raise ValueError(
ValueError: Specified type 'google_ads_failure' does not exist in Google Ads API v8
failure_message = gAdsServiceWrapper.client.get_type("google_ads_failure")
I think this should be -
failure_message = gAdsServiceWrapper.client.get_type("GoogleAdsFailure")
Can someone please tell me why this error occurs while converting 'mp4' to 'mp3'? And also how to resolve this.
Traceback (most recent call last):
File "C:\Users\Pranjal\AppData\Local\Programs\Python\Python39\lib\site-packages\moviepy\audio\AudioClip.py", line 200, in
codec = extensions_dict[ext[1:]]['codec'][0]
KeyError: ''
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\Pranjal\Documents\Python\filemvidaud.py", line 14, in <module>
au.audio.write_audiofile(b)
File "<decorator-gen-45>", line 2, in write_audiofile
File "C:\Users\Pranjal\AppData\Local\Programs\Python\Python39\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
File "C:\Users\Pranjal\AppData\Local\Programs\Python\Python39\lib\site-packages\moviepy\audio\AudioClip.py", line 202, in write_audiofile
raise ValueError("MoviePy couldn't find the codec associated "
ValueError: MoviePy couldn't find the codec associated with the filename. Provide the 'codec' parameter in write_audiofile.
I'm trying to get this, https://github.com/joaquinlpereyra/twitterImgBot, to work
and it works and it seems ok.
But after some hours, it stops working and this error comes up:
*python3 twitterbot.py
Traceback (most recent call last):
File "/home/user/.local/lib/python3.7/site-packages/tweepy/binder.py", line 118, in build_path
value = quote(self.session.params[name])
KeyError: 'id'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "twitterbot.py", line 209, in <module>
main()
File "twitterbot.py", line 200, in main
orders()
File "twitterbot.py", line 118, in orders
timeline.delete_tweet_by_id(tweet.in_reply_to_status_id, api)
File "/home/user/Skrivebord/twitterboot/lo/bot/timeline.py", line 12, in delete_tweet_by_id
api.destroy_status(id_to_delete)
File "/home/user/.local/lib/python3.7/site-packages/tweepy/binder.py", line 245, in _call
method = APIMethod(args, kwargs)
File "/home/user/.local/lib/python3.7/site-packages/tweepy/binder.py", line 71, in __init__
self.build_path()
File "/home/user/.local/lib/python3.7/site-packages/tweepy/binder.py", line 120, in build_path
raise TweepError('No parameter value found for path variable: %s' % name)
tweepy.error.TweepError: No parameter value found for path variable: id*
It seems like the Python has some problem because if I make a new install on a another PC it works for some hours and then stops.
Strange.
This is likely because tweet is not in reply to a status, so has an in_reply_to_status_id attribute that's None, so API.destroy_status is called with an id of None.