I have somehow encountered a null byte into my code and i am getting this error:
File "py.py", line 7, in <module>
import mysql.connector
ValueError: source code string cannot contain null bytes
This is the code which is producing error:
from time import sleep
import sys
import requests, json
from datetime import datetime as dt
from datetime import timedelta
import threading
import mysql.connector
print('ok')
However, removing the line 'import mysql.connector' the program works just fine?
any suggestions?
I tried removing the error by using this answer but it did not work?
any suggestions?
I tried to reinstall the mysql-connector-python library. It worked just fine :/
Related
Traceback (most recent call last):
File "gen.py", line 9, in <module>
from SeleniumHelper import SeleniumHelper
ImportError: No module named 'SeleniumHelper'
# python accounts.py -i ../../data/twitter-creator.json -d regular -f 1
# python accounts.py -i ../../data/twitter-creator.json -d proxy -f 1
import sys
import time
import getopt
import simplejson
from selenium import webdriver
from seleniumHelper import seleniumHelper
class TwitterCreator(SeleniumHelper):
MOBILE_URL_CREATE = 'https://mobile.twitter.com/signup?type=email'
MOBILE_FIELD_SIGN_UP_NAME = '#oauth_signup_client_fullname'
MOBILE_FIELD_SIGN_UP_EMAIL = '#oauth_signup_client_phone_number'
MOBILE_FIELD_SIGN_UP_PASSWORD = '#password'
MOBILE_FIELD_SIGN_UP_USERNAME = '#custom_name'
MOBILE_BUTTON_SKIP_PHONE = '.signup-skip input'
MOBILE_BUTTON_INTERESTS = 'input[data-testid="Button"]'
DESKTOP_URL_CREATE = 'https://twitter.com/signup'
DESKTOP_URL_SKIP = 'https://twitter.com/account/add_username'
DESKTOP_URL_MAIN = 'https://twitter.com'
import mechanize
import cookielib
import subprocess
dear python masters. I am getting selenium helper error. I posted the error above. I tried hard to decode the code. but I couldn't find where is the error. where is the problem? I will be very happy if you answer. good work.
note:there is also another file called selenium. I put the error code at the top.
note2: I installed selenium with pip. but he doesn't see.
from SeleniumHelper import SeleniumHelper
--this is improper syntax. Ostensibly you could do import SeleniumHelper as SeleniumHelper? I'm not sure how this differs from simply import SeleniumHelper anyway.
I am trying to execute this code in Visual Studio Code, the code works, my problem is related to the import of numpy; the other imports are working.
import codecs
from operator import le
import string
from struct import unpack
import paho.mqtt.client as mqtt
import struct
import numpy as np
def on_connect1(client1, userdata1, flags1, rc1):
client1.subscribe("MYTOPIC")
def on_message1(client1, userdata1, msg1):
#print(msg1.topic+" "+ "TERMORESISTENZA: "+str(msg1.payload))
Byte_Order = '<' # little-endian
Format_Characters = 'f' # float (4 bytes)
data_format = Byte_Order + Format_Characters
r = np.array(list(struct.iter_unpack(data_format, msg1.payload)), dtype=float)
print(r)
When I run the code it returns me this error:
ModuleNotFoundError: No module named 'numpy'
Any suggestions?
I used the Windows Command Prompt to install numpy with the command:
pip install numpy
and solved the problem
I'm running python 3.4 under Win7.
Why does 'import urllib' fail if 'import matplotlib' is absent?
import urllib
import socket
import sys, os
import matplotlib.pyplot # urllib won't work unless this is here ! WTF?? !
url='https://finance.yahoo.com/quote/SPY/history?period1=1410652800&period2=1536883200&interval=1d'
bytes = urllib.request.urlopen(url, timeout=4).read()
page = str( bytes, encoding='utf8' )
print("Page length="+str(len(page)))
sys.exit
Without import matplotlib.pyplot, program fails with this error:
File "C:\Python34\minibigdrops.py", line 8, in module
bytes = urllib.request.urlopen(url, timeout=4).read()
AttributeError: 'module' object has no attribute 'request'
The other attributes, like 'error', aren't found either.
I see that several others have posted problems with urllib. Perhaps they could try also importing matplotlib.
I am trying to import a custom function from another python file but keep getting an error NameError: name 'testme' is not defined. I confirmed that I am importing the file correctly according to this SO post and that the function is top level. What else can I try to fix this?
My main python file is:
import sys
import dbconn
#from dbconn import testme #<----did not work
dev=True
if(dev):
categId='528'
pollIds=[529,530,531]
else:
categId=str(sys.argv[1])
pollIds=[529,530,531]
df=testme(categIds)#callServer(categId,pollIds)
df
if(not categId.isdigit):
print('categ id fail. expected digit got: '+categId)
.....
and dbconn.py:
import pymysql #pip3 install PyMySQL
import pandas as pd
from scipy.stats.stats import pearsonr
from scipy import stats
def testme(categIds):
try:
df=categIds
except Exception as e:
print("broke")
return categIds
Not sure if it makes a difference but I am running the main python file from within a Jupyter notebook, and have a compiled version of dbconn.py in the same directory
In response to the suggestions I tried:
df=dbconn.testme(categIds)
got the error:
module 'dbconn' has no attribute 'testme'
You Have to follow these fox exact import
1)import <package>
2)import <module>
3)from <package> import <module or subpackage or object>
4)from <module> import <object>
in your case, you have tried
from dbconn import testme
you have to use only packages in from section and module in import section
like >>
from testme import dbconn
Chaps I am going through what is apparently a #1 problem for python novice. I have been through some tutorials but I really can t get it works. Here is the code :
import time
from settings import *
from actif_class import *
from get_settings import *
from dataython import *
from spreadython import *
from tankython import *
if __name__ == "__main__":
t0 = time.clock()
settings = get_settings()
tickers = get_data_mp(settings)
list_spreads = get_list_spread(tickers,settings)
list_spreads_tank = tanking(list_spreads,settings)
spread_traitable = obtention_spreads_traitables(list_spreads_tank,settings)
print 'done. Timing',time.clock()-t0,'seconds'
and here is the stack :
ImportError: No module named datayhton
Even though the module DOES exist and is in the same folder as every other modules. It is able to see the get_settings one but not dataython. I ve tried on another machine but still got the same trouble.
I tried to go through import sys, sys.path.append but I might have done something wrong because it still doesnt work.
Any help would be much appreciated.
EDIT : still doesnt work when I write this on top of my code :
import time
import sys
sys.path.append("/path/to/dataython")
Ok. I got it now. Not a no brainer so here is the amended code :
import time
import sys
sys.path.append("path/to/your/file")
import your_file
the mistake I was doing was keep writing :
from your_file import *