Hierarchical clustering with precomputed cosine similarity matrix using scikit learn produces error
According to sklearn's documentation:


  If linkage is “ward”, only “euclidean” is accepted. If
  “precomputed”, a distance matrix (instead of a similarity matrix) is
  needed as input for the fit method.


So you need to change the linkage to one of complete, average or single. If you try this it works:

import numpy as np 
from sklearn.cluster import AgglomerativeClustering

X = np.array([[0,0.3,0.4],[0.3,0,0.7],[0.4,0.7,0]])

#cluster = AgglomerativeClustering(affinity='precomputed', linkage='complete') 
#cluster = AgglomerativeClustering(affinity='precomputed', linkage='average')
cluster = AgglomerativeClustering(affinity='precomputed', linkage='single')
cluster.fit(X)